you can use middleware, since middleware supports parameter passing
class CheckPrivacy
{
public function handle($request, Closure $next, $userId)
{
$user = User::find($userId);
if (Auth->user()->hasBlocked($user)) {
abort(403);
}
return $next($request);
}
}
see this https://www.laravel.com/docs/5.3/middleware#middleware-parameters
on your controllers you can check like this
$this->middleware('checkPrivacy:'.$userId)
Great, thanks! Middleware is a good enough solution. I've used it in routes instead in controller.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community