vendredi 1 février 2019

Laravel 5.7 guard and middleware are not working


laravel Guard or middleware is not working .
my admin panel is always visiable in auth or non-auth.
i don't understand , what is the problem ?

Route:

Route::get('/admin', 'admin\adminController@index')->middleware('auth:admin');
    Route::get('/admin-login', 'auth\adminLoginController@index');
    Route::post('/admin-login', 'auth\adminLoginController@login')->name('admin.login.submit');

my controller's code : auth/adminLoginController

namespace App\Http\Controllers\auth;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Auth;

class adminLoginController extends Controller
{
    function __construct()
    {
        $this->middleware('guest:admin');
    }

    public function index()
    {
        return view('auth.admin-login');
    }

public function login(Request $request) {

        // Validate Data...
        $this->Validate($request,[
            'email'=>'required|email',
            'password'=>'required|min:6'
        ]);

   // checking...
  if(Auth::guard('admin')->attempt(['email' => $request->email, 'password' => $request->password], false, false)) {
     return redirect('/admin');
  } else {
    return redirect()->back()->with('message', 'Invalid Information');
 }
}
}

If i delete __construct() , then i can visit admin log-in page , otherwise i cannot go in !!

my code of auth.php :


Guards :

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],
    'api' => [
        'driver' => 'token',
        'provider' => 'users',
    ],

    'admin' => [
        'driver' => 'session',
        'provider' => 'admins',
    ],

    'admin-api' => [
        'driver' => 'token',
        'provider' => 'admins',
    ],

],


Providers :

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\User::class,
    ],

    'admins' => [
        'driver' => 'eloquent',
        'model' => App\admin::class,
    ],
],

my adminControllers code :
admin is always visiable in auth or without auth

namespace App\Http\Controllers\admin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\User;

class adminController extends Controller
{
    public function index()
    {
        $user = User::all();
        $maleuser = User::where('gender','male')->get();
        $femaleuser = User::where('gender','female')->get();
        return view('admin/index')
                ->with('users',$user)
                ->with('maleusers',$maleuser)
                ->with('femaleusers',$femaleuser);
    }
}

Iam tried for solved issu . Iam not a expert developer . please help me !!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire