Category Archives: PHP

取得route中設定的網址參數

Route

Controller

 

Escape Like

Helper

Reference:

laravel-permission

Official

https://github.com/spatie/laravel-permission

Doc

https://docs.spatie.be/laravel-permission/v3/basic-usage/role-permissions/

Model User

Config “Super Admin” in AuthServiceProvider.php

Controller and related functions

Add useful function in model User

 

 

Disable CSRF check for some route (page)

Reference:

Filter and Redirect Middleware

Middleware

Kernel

Route:

 

logg

 

Creating thumbs using Intervention\Image

 

Controller

Using Storage

 

Laravel Eloquent Auto Delete problem

Model

Controller:

 

Change DB connection on the fly

Amazing solution:

Test function

Global Middleware

app/Http/Kernel.php

The position you put the middleware in is critical. Since cookie is used in the middleware, you can’t put it in global middleware because cookie and session are not activated yet.

The correct position is in “web” group

https://laracasts.com/discuss/channels/laravel/session-doesnt-work-in-middleware

Reference:

  1. https://stackoverflow.com/questions/31041893/laravel-change-database-connection-run-time
  2. Override DB facade
    https://stackoverflow.com/questions/40614875/laravel-5-extend-a-facade/40615078#40615078
  3. Extending DB facade
    https://stackoverflow.com/questions/52944843/extending-db-facade-laravel
  4. Change database configs
    https://laracasts.com/discuss/channels/eloquent/how-to-modify-database-connection-string-in-laravel-5
  5. Extend model (For eloquent)
    https://stackoverflow.com/questions/28985472/change-database-connection-in-laravel-model