Postingan lainnya
Middleware di fungsi construct controller Laravel 11
Saya mendapatkan error undefined middleware
saat melaukannya di fungis __construct()
di Laravel 11 (Inertia React)
public function __construct()
{
$this->middleware('auth')->except(['index', 'show']);
}
0
1 Jawaban:
Ini cara menggunakan middlware di Controller di Laravel 11:
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Routing\Controllers\HasMiddleware;
use Illuminate\Routing\Controllers\Middleware;
class UserController extends Controller implements HasMiddleware
{
/**
* Get the middleware that should be assigned to the controller.
*/
public static function middleware(): array
{
return [
'auth',
new Middleware('log', only: ['index']),
new Middleware('subscribed', except: ['store']),
];
}
// ...
}
0