php Laravel ~ Attribute [controller] does not exist
35,861
The controller method is deprecated since Laravel 5.3. But now, you can use the resource method, which is meant for the same purpose as the controller method.
Like This:
Route::resource('auth', 'LoginController');
or
Route::get('/auth','LoginController');
Route::post('/auth','LoginController');
Author by
cmiotk
Updated on August 24, 2020Comments
-
cmiotk over 3 years
I am trying to set up an Route Controller in my Laravel project and I have set up the controller and also the route.
However, when I load the route in the
web.php
then it produces an error when I try to navigate to that page in the browser ofAttribute [controller] does not exist
Here is the code..
<?php namespace CMS\Http\Controllers\Auth; use CMS\Http\Controllers\Controller; use Illuminate\Foundation\Auth\AuthenticatesUsers; class LoginController extends Controller { use AuthenticatesUsers { logout as performLogout; } /** * Where to redirect users after login. * */ protected $redirectTo; /** * Create a new controller instance. * */ public function __construct() { $this->redirectTo = route('backend.dashboard'); $this->middleware('guest')->except('logout'); } public function logout(Request $request) { $this->performLogout($request); return redirect()->route('auth.login'); } }
And then in the web.php I have this...
Route::controller('auth', 'Auth\LoginController', [ 'getLogin' => 'auth.login' ]);
-
Muhammad Rizwan almost 7 yearsIn laravel 5.2 , controller method is working, now by using controller method in laravel 5.4 , it gives the same attribute controller error. Thanks for your answer.
-
Dylan Glockler about 2 yearsHm that's odd, the Laravel 8 router documentation uses it for routing by groups: laravel.com/docs/8.x/routing#route-groups