“Laravel Middleware” Kode Jawaban

Laravel Middleware di Konstruktor

public function __construct(User $user)
{
  	$this->user = $user;
  
    $this->middleware(function ($request, $next) {
        $user = auth()->user();
        if ($user) {
          	$this->user = $user;
        }
      
        return $next($request);
    });
}
Almabek

Laravel Make: Middleware

php artisan make:middleware AdminMiddleware
Different Dogfish

Perintah untuk membuat middleware di Laravel

php artisan make:middleware MiddlewreName
Isaac

Laravel Middleware

Route::get('/profile', function () {
    //
})->middleware('auth');
Poor Pigeon

Laravel Make: Middleware

public function handle($request, Closure $next)
{
    if ($request->user()->type != 'A')
    {
        return redirect('home');
    }

    return $next($request);
}
Different Dogfish

Laravel Make: Middleware

Route::group(['middleware' => 'App\Http\Middleware\AdminMiddleware'], function()
{
    Route::get ('/admin', ['uses' => 'AdminController@index', 'before' => 'admin']); 

});
Different Dogfish

Jawaban yang mirip dengan “Laravel Middleware”

Pertanyaan yang mirip dengan “Laravel Middleware”

Lebih banyak jawaban terkait untuk “Laravel Middleware” di PHP

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya