Q:

Laravel authentication admin area

im looking to be pointed in the direction for my site. I'm trying to use laravel authentication , however  dont need to be able to register users. I just need to be able to login to get to the admin area. how could I do this?
I am using laravel 5.2

A:

You could either use the auth scaffold that Laravel provides and just use the normal users as admin users since your application won't register new users anyway. Here is an alternative way
class AdminsController extends Controller
{
    public function getLogin()
    {
        return view('admin.login');
    }

    public function postLogin(Request $request)
    {
        $this->validate($request, ['email' => 'required|email', 'password' => 'required']);

        if(!Auth::attempt(['email' => $request['email'], 'password' => $request['password']])) {
            return redirect()->back()->with(['fail' => 'Could not log you in!']);
        }

        return redirect()->route('admin.dashboard');

    }

    public function getLogout()
    {
            Auth::logout();
            return redirect()->route('index');
    }
}

And in the routes.php :
Route::group(['middleware' => ['guest']], function () {

    Route::get('/admin/login', [
        'uses' => 'AdminsController@getLogin',
        'as' => 'admin.login'
    ]);

    Route::post('/admin/login', [
        'uses' => 'AdminsController@postLogin',
        'as' => 'admin.login'
    ]);
});

Route::group(['middleware' => ['auth']], function () {
    Route::get('/admin/logout', [
        'uses' => 'AdminsController@getLogout',
        'as' => 'admin.logout'
    ]);
});

Hope you get around with this code and that it was helpful. 

