簡體   English   中英

中間件對於控制器中的操作,Laravel 5.1

[英]Middleware For actions into Controller, Laravel 5.1

我有一個具有索引方法的Controller,但也具有可以訪問此方法的多個級別的用戶,但是一個管理員可以查看數據庫的所有記錄。如何添加中間件來選擇與用戶相對應的操作? 我有下一個代碼

<?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 a listing of the resource.
 *
 * @return Response
 */

public function index()
{
    $labs = Lab::all();
    return view('comp.lab.index',['labs' => $labs]);
}

/**
 * Show the form for creating a new resource.
 *
 * @return Response
 */
public function create()
{
    return view('comp.lab.create');
}

/**
 * Store a 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 the specified resource.
 *
 * @param  int  $id
 * @return Response
 */
public function show()
{
     $teams = $this->laboratorio;
    return view('comp.lab.show',['lab'=>$this->laboratorio]);
}

/**
 * Show the form for editing the specified resource.
 *
 * @param  int  $id
 * @return Response
 */
public function edit()
{
    return view('comp.lab.edit',['lab'=>$this->laboratorio]);
}

/**
 * Update the 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 the specified resource from storage.
 *
 * @param  int  $id
 * @return Response
 */
public function destroy()
{
    $this->laboratorio->delete();
    Session::flash('message','El laboratorio fue eliminado correctamente');
    return Redirect::to('/laboratorio');
}

感謝:D

這是一個總體思路:

$user_group = $user::get_user_group($user_id)
if($user_group->group_id === 'something'){
    \\method to return data for group 'something'
}

按組獲取數據

$user_data = $user::get_data_by_group_id($group_id)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM