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 of Attribute [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'
]);
“Target class Controller does not exist” issue comes in Laravel 8. One simple trick can solve this issue. This error comes in Laravel new version because there is no namespace prefix being applied to your route groups that your routes are loaded into.
To Solve Target class controller does not exist in Laravel 8 Error In Laravel 8 You have to use Route as given Below: Route::get('/register', 'App\Http\Controllers\UserController@register'); OR use App\Http\Controllers\UserController; Route::get('/register', [UserController::class, 'register']); Now, your error must be ...
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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With