framework icon indicating copy to clipboard operation
framework copied to clipboard

Call to undefined method ::middleware() when calling authorizeResource()

Open MichaelRushton opened this issue 1 year ago • 0 comments

Laravel Version

11

PHP Version

8.3

Database Driver & Version

No response

Description

Calling authorizeResource() in a resource controller throws a "Call to undefined method ::middleware()" exception.

Steps To Reproduce

Route::apiResource("/users", UserController::class);
abstract class Controller
{
    use AuthorizesRequests;
}
class UserController extends Controller
{
    public function __construct()
    {
        $this->authorizeResource(User::class, "user");
    }
}
[2024-03-14 21:45:45] testing.ERROR: Call to undefined method App\Http\Controllers\UserController::middleware() {"exception":"[object] (Error(code: 0): Call to undefined method App\\Http\\Controllers\\UserController::middleware() at /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Auth/Access/AuthorizesRequests.php:100)

MichaelRushton avatar Mar 14 '24 21:03 MichaelRushton