notes
  • computer-networking
    • extend-wifi-with-router
    • how-the-internet-works
    • idk
    • networking-devices
    • osi-model
    • tcp-ip
    • Types of VPN
  • databases
    • Foreign Keys
    • Redis
    • simple-queries
  • devops
    • ansible
    • Manual deployment
    • docker
    • Workflow file
    • nginx
    • promethues-grafana
    • terraform
  • hardware
    • Power
  • home-server
    • proxmox-basics
    • proxmox-setup
    • storage
  • languages-frameworks
    • programming-paradigms
    • programming-languages
      • Regex Notes
      • c
        • basics
        • pointers-memory
      • cpp
        • basics
        • running-cpp
      • php
        • basics
        • choizez
        • frameworks
          • laravel
      • python
        • venv
        • concepts
          • Using lambda
        • frameworks
          • django
            • django
            • start
      • java
        • advanced
          • functional-programming
          • reactive-programming
        • concepts
          • how-java-works
          • serialization
          • sockets
          • threads
        • extra
          • collection-framework
          • generics-and-wildcards
          • Regular Expressions (Regex)
          • streams
        • frameworks
          • orm
        • fundamentals
          • OOP
          • conditionals
          • data-structures
          • data-types
          • exceptions
          • files
          • Functions (aka method)
          • Loops
          • packages
          • type-casting
      • javascript
        • frameworks
          • morgan
          • Using Sequelize with PostgreSQL in JavaScript
  • operating-system
    • basics
    • linux-directories
    • Basic Unix Terminal Commands
  • others
    • dark-web
    • piracy
  • system-design
    • system-design
  • web-dev
    • full-stack
  • books
    • sicp
      • Recursion thought process
      • 1
        • 1.1
        • 1.2
        • 1.3
      • 2
        • 2.1
  • certifications
    • aws-certified-cloud-practitioner
      • core-services
      • other-services
    • comptia-a+
      • Cloud
      • hardware
      • Important terms
      • Important terms
      • Troubleshooting
  • cloud
    • aws
      • aws-cli
      • aws-ec2-deployment
  • dsa
    • algorithms
      • back-tracking
      • bfs
      • Binary Search
      • bit-manipulation
      • Bubble sort
      • bucket-sort
      • counting-sort
      • dfs
      • Divide & Conquer
      • djikstras-algorithm
      • dynamic-programming
      • external-sorting
      • greedy-algorithm
      • Heap sort
      • Insertion sort
      • kadanes-algorithm
      • Merge sort
      • Permutation
      • quick-sort
      • Radix Sort
      • recurrence-relation
      • recursion
      • Selection sort
      • sliding-window
      • subset
      • time-space-complexity
      • topological-sort
      • tree-traversals
      • Two Pointers Technique
    • data-structures
      • data-structures
  • security
    • authentication
      • What is JWT (JSON Web Token)?
    • software-architecture-design
      • design-patterns
Powered by GitBook
On this page
  • Connect to DB
  • Create model migration
  • Example (Create list Item , add to DB)
  1. languages-frameworks
  2. programming-languages
  3. php
  4. frameworks

laravel

PreviousframeworksNextpython

Last updated 1 month ago

  1. Install PHP using XAMPP

  2. Install COMPOSE (PHP dependecy manager)

  3. Run below to create a laravel app named example-app

composer create-project laravel/laravel example-app
cd example-app

Connect to DB

// Can now run laravel web app using
php artisan serve

To connect to mySQL database: I use mySQL workbench Connect a connection Create a database eg.

Add database details to .env file

Create model migration

php artisan make:model ListItem -m

// This creates a ListItem model (/app/Models)

// and a migration file (/database/migrations) where I can configure the table columns which will be created
php artisan migrate

//Migrate meaning create tables in connected database

Now my database looks like this , because there are multiple default tables

Example (Create list Item , add to DB)

// welcome.blade.php file

<body>
  <h1>To do list</h1>

  <form method="POST" action="/list-items" accept-charset="UTF-8">
    @csrf
    <label for="listItem">New todo Item</label>
    <input type="text" name="listItem" required />
    <button type="submit">Add Item</button>
  </form>
</body>
//web.php

Route::post('/list-items', [TodoListController::class, 'store']);
//TodoListController.php

class TodoListController extends Controller
{
    public function store(Request $request)
    {
        $request->validate([
            'listItem' => 'required|string|max:255',
        ]);

        $listItem = new ListItem();
        $listItem->name = $request->input('listItem');
        $listItem->is_complete = 0; // Default to not completed
        $listItem->save();

        return redirect()->back()->with('success', 'Item added successfully!');
    }
}
alt text
alt text
alt text
alt text