Class 'App \ Http \ Controllers \ admin \ Auth' not found in laravel 5

I get an error, for example Class 'App \ Http \ Controllers \ admin \ Auth' was not found in laravel 5 during login. I am new to laravel, so please help me or give me a link to a tutorial for the full development of laravel applications with administrative side.

routes.php

Route::group(array('prefix'=>'admin'),function(){ Route::get('login', 'admin\ AdminHomeController@showLogin '); Route::post('check','admin\ AdminHomeController@checkLogin '); }); 

Adminminomecontroller.php

 <?php namespace App\Http\Controllers\admin; use App\Http\Requests; use App\Http\Controllers\Controller; use Illuminate\Http\Request; class AdminHomeController extends Controller { // public function showLogin() { return view('admin.login'); } public function checkLogin(Request $request) { $data=array( 'username'=>$request->get('username'), 'password'=>$request->get('password') ); if(Auth::attempt($data)) { return redirect::intended('admin/dashboard'); } else { return redirect('admin/login'); } } public function logout() { Auth::logout(); return redirect('admin/login'); } public function showDashboard() { return view('admin.dashboard'); } } 

login.blade.php

 <html> <body> {!! Form::open(array('url' => 'admin/check', 'id' => 'login')) !!} <input type="text" name="username" id="username" placeholder="Enter any username" /> <input type="password" name="password" id="password" placeholder="Enter any password" /> <button name="submit">Sign In</button> {!! Form::close() !!} </body> </html> 
+5
source share
1 answer

Since your controller is in the namespace, unless you specifically import the Auth namespace, PHP will read it under the class namespace, indicating this error.

To fix this, add use Auth; to the top of the AdminHomeController file along with your other use operations or, alternatively, prefix all instances of Auth with a backslash as follows: \Auth so that PHP knows to load it from the global namespace.

+15
source

Source: https://habr.com/ru/post/1214996/


All Articles