I'm able to login normally in Laravel, But i want to Login using Modal pop up. When i click on login button i want all types of remote validations done without manipulating codes in auth. This is my working code:
LoginController.php
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
login.blade.php
<div class="tab-pane active" id="login-form" role="tabpanel">
<form action="" method="POST" role="form">
@csrf
<h5 class="heading-design-h5 text-dark">LOGIN</h5>
<fieldset class="form-group mt-4">
<label>Enter Email/Mobile number</label>
<input type="email" class="form-control" name="email" id="email" value="">
</fieldset>
<fieldset class="form-group">
<label>Enter Password</label>
<input type="password" class="form-control" name="password" id="password">
</fieldset>
<fieldset class="form-group">
<button type="submit" class="btn btn-lg btn-primary btn-block">Enter to your account</button>
</fieldset>
</form>
routes.php
Auth::routes();
RedirectIfAuthenticated.php
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
switch($guard){
case 'admin':
if (Auth::guard($guard)->check()) {
return redirect('/admin');
}
break;
default:
if (Auth::guard($guard)->check()) {
return redirect('/');
}
break;
}
return $next($request);
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire