i've two models, Admin.php & Role.php. there are three tables admins , roles & a pivot table admins_roles. there are two roles in my application, notary & title_officer. i've created middlewares to check the admins according to their roles and redirect them to intended url. but when an authenticated admin logs in, there is only blank page i can see, instead of redirected dashboard. there is no error my application is showing. it's just showing me blank page. how can i fix it ?
Notary middleware ->
<?php
namespace App\Http\Middleware;
use Closure;
use Auth;
class Notary
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if(Auth::check() && Auth::user()->role()){
return $next($request);
}else{
return redirect()->back();
}
}
}
Officer middleware ->
<?php
namespace App\Http\Middleware;
use Closure;
use Auth;
class Officer
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if(Auth::check() && Auth::user()->role()){
return $next($request);
}else{
return redirect()->back();
}
}
}
Admin model ->
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
class Admin extends Authenticatable
{
use Notifiable;
protected $guard = 'admin';
protected $fillable = [
'name', 'email', 'password',
];
protected $hidden = [
'password', 'remember_token',
];
public function role()
{
return $this->belongsToMany('App\Role','admins_roles');
}
}
Role model ->
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Role extends Model
{
public function admins()
{
return $this->belongsToMany('App\Admin','admins_roles');
}
}
the route i'm using the officer middleware ->
Route::resource('order', 'BackendController')->middleware('officer');