php - Middleware For actions into Controller, Laravel 5.1 -
i have controller have index method, have multiple levels of users have access method, single admin can view records of database how can add middleware select action corresponding user? have next code
<?php namespace set\http\controllers; use illuminate\http\request; use illuminate\support\facades\session; use illuminate\support\facades\redirect; use set\http\requests; use set\http\requests\labrequest; use set\http\controllers\controller; use illuminate\routing\route; use set\lab; use validator; use auth; use db; class laboratoriocontroller extends controller { public function __construct(){ $this->beforefilter('@find', ['only' => ['show','edit','update','destroy']]); } public function find(route $route){ $this->laboratorio = lab::findorfail($route->getparameter('laboratorio')); } /** * display listing of resource. * * @return response */ public function index() { $labs = lab::all(); return view('comp.lab.index',['labs' => $labs]); } /** * show form creating new resource. * * @return response */ public function create() { return view('comp.lab.create'); } /** * store newly created resource in storage. * * @return response */ public function store(labrequest $request) { lab::create($request->all()); session::flash('message','laboratorio creado correctamente'); return redirect::to('/laboratorio'); } /** * display specified resource. * * @param int $id * @return response */ public function show() { $teams = $this->laboratorio; return view('comp.lab.show',['lab'=>$this->laboratorio]); } /** * show form editing specified resource. * * @param int $id * @return response */ public function edit() { return view('comp.lab.edit',['lab'=>$this->laboratorio]); } /** * update specified resource in storage. * * @param int $id * @return response */ public function update(labrequest $request) { $this->laboratorio->update($request->all()); session::flash('message','el laboratorio se actualizo correctamente'); return redirect::to('/laboratorio'); } /** * remove specified resource storage. * * @param int $id * @return response */ public function destroy() { $this->laboratorio->delete(); session::flash('message','el laboratorio fue eliminado correctamente'); return redirect::to('/laboratorio'); }
thanks :d
here's general idea:
$user_group = $user::get_user_group($user_id) if($user_group->group_id === 'something'){ \\method return data group 'something' }
get data groups
$user_data = $user::get_data_by_group_id($group_id)
Comments
Post a Comment