Hi,
This can be solved pretty easily by using Middleware (http://laravel.com/docs/5.0/middleware)
First lets create the middleware, you can call it whatever, let's say AdminMiddleware:
php artisan make:middleware AdminMiddleware
Now that we have our middleware, we need to edit it and specify what we want it to do.
In App\Http\Middleware you should see the newly created file
<?php namespace App\Http\Middleware;
use Closure;
class AdminMiddleware {
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($request->user()->type != 'A')
{
return redirect('home');
}
return $next($request);
}
}
What we are doing here, is taking the user and checking to see if the type is A if not.. redirect home.
Now that we have that, we need to use it in the routes.php file.
Route::group(['middleware' => 'App\Http\Middleware\AdminMiddleware'], function()
{
Route::get('/admin', function()
{
// can only access this if type == A
});
});
Hopefully that helps!
willstumpf an absolute legend thanks, so much works perfectly!
Really appreciate you help. :)
drc83 said:
willstumpf an absolute legend thanks, so much works perfectly!
Really appreciate you help. :)
How did you manage to implement checking of user type?
Auth::user()->type;
orsic said:
drc83 said:
willstumpf an absolute legend thanks, so much works perfectly!
Really appreciate you help. :)
How did you manage to implement checking of user type?
Auth::user()->type;
I'm using "zizaco/entrust" for user types
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community