---
# System prepended metadata

title: Laravel controller

---

# Laravel controller
## Controller cơ bản
https://laravel.com/docs/7.x/controllers
Cách tạo:
```bash
php artisan make:controller UserController
```
```php=
<?php
 
namespace App\Http\Controllers;
 
use App\Http\Controllers\Controller;
use App\User;
 
class UserController extends Controller
{
    /**
     * Show the profile for the given user.
     *
     * @param  int  $id
     * @return View
     */
    public function show($id)
    {
        return view('user.profile', ['user' => User::findOrFail($id)]);
    }
}

```

## Resource Controllers
Cách tạo
```
php artisan make:controller PhotoController --resource
php artisan make:controller SchoolController --model=Models\\School --resource
```
## Dependency Injection
https://blog.pirago.vn/service-container-trong-laravel/