> For the complete documentation index, see [llms.txt](https://aloy.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://aloy.gitbook.io/notes/languages-frameworks/programming-languages/php/frameworks/laravel.md).

# laravel

1. Install PHP using XAMPP
2. Install COMPOSE (PHP dependecy manager)
3. Run below to create a laravel app named example-app

```php
composer create-project laravel/laravel example-app
```

4.

```php
cd example-app
```

## Connect to DB

```php
// 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.

![alt text](/files/LAR0WbjlPWfD4PTTW01Y)

Add database details to .env file

![alt text](/files/9YAuwYXIt9GUQI2DEPWq)

## Create model migration

```php
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
php artisan migrate

//Migrate meaning create tables in connected database
```

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

![alt text](/files/0rsaeiadTU1ReHpPlF16)

![alt text](/files/KssN1fQ8rQOcR0pbS9h5)

## Example (Create list Item , add to DB)

```php
// 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>
```

```php
//web.php

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

```php
//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!');
    }
}

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://aloy.gitbook.io/notes/languages-frameworks/programming-languages/php/frameworks/laravel.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
