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']);
    }
avatar yuxxeun
@yuxxeun

98 Kontribusi 50 Poin

Diperbarui 2 hari yang lalu

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']),
        ];
    }
 
    // ...
}

Dokumentasi

avatar hilmanski
@hilmanski

2692 Kontribusi 2138 Poin

Dipost 2 hari yang lalu

Login untuk ikut Jawaban