Laravel Command
Tools
Lang
- Laravel Lang
- composer require caouecs/laravel-lang:~3.0
- second way to change language is to put json language file to lang folder
Services
- Auth
- attempt(): to login and register session data. Verify email and unencrypted password
- logout()
Migration
1 | * php artisan make:migration UserTestTable |
FORM CRUD
- @csrf @method(‘DELETE’): filter request
- csrf
- php artisan make:policy PostPolicy: to avoid not authorize user to delete
- using @can(‘delete’, $user) to toggle delete button
- @csrf @method(‘PUT’): fake update method using put instead
- Method Field
Helpers
Artisan Command
1 | php artisan make:controller IndexController |
Session Driver
- change .env session_driver to session
- laravel will create sessoin table to record user login message
- once you change the driver type, you need to refresh all record to get the correct result
1 | php artisan session:table |
Create App Key & Smtp Setting
1 | php artisan key:generate |
- env.php
- MAIL_DRIVER=smtp
- MAIL_HOST=smtp.gmail.com
- MAIL_PORT=587
- MAIL_USERNAME=your@gmail.com
- MAIL_PASSWORD=yourgmailpassword
- MAIL_ENCRYPTION=tls
create factory data
1 | // manually added records |
1 | // execute by db:seed |
Using Policy
- create policy
- php artisan make:policy --model=user UserPolicy
- AuthServiceProvider add Policy
- ‘App\User’ => UserPolicy::class,
- remember to add namespace before using this policy
- authorize controller destroy method to execute delete method
- $this->authorize(‘delete’, $user);
Notice
- routes/web.php
- use get to access controller function
- alias name for changing back to home page
- use resource to create default CRUD method
- no need to create additional view blade files
- laravel 5.4 support emoji for MySQL 5.7.7
- every time start the app
- Providers\AppServiceProvider.php
- config\app.php
1 | Route::get('/', 'IndexController@home')->name('home'); |
1 | public function boot() |