Category Archives: Laravel

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:

 

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

Apply Middleware to Route

1. Create a middleware

2. Modify middleware MmeberInfo
To share logged in member data to all views in the group

3. Add this middleware to /app/Http/Kernel.php

4. Apply this middleware to route

After apply this middleware, every controller and view in the route group are able to access $member variable easily.

Reference:

Common classes for Laravel