21
votes

i am getting error like Class 'App\Http\Controllers\admin\Auth' not found in laravel 5 while login. i am new to laravel so please help me or give me some tutorial link for complete laravel application development with admin side

Routes.php

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

AdminHomeController.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>
1

1 Answers

74
votes

Because your controller is namespaced unless you specifically import the Auth namespace, PHP will assume it's under the namespace of the class, giving this error.

To fix this, add use Auth; at the top of AdminHomeController file along with your other use statements or alternatively prefix all instances of Auth with backslash like this: \Auth to let PHP know to load it from the global namespace.