• 7

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 187


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 187
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Laravel middleware get route parameter

I am coding some thing like 'school club manage system' and meet some problem on rights authorization of resource .

Suppose there are club , and club have manager , and i want to check if the user is a manager of club before he can manage it with a middleware.

Using laravel 5.2

My router looks like that :

Route::resource('club', 'ClubController');

The middleware I create looks like that :

  public function handle($request, Closure $next)
        if (!Auth::check()){
            // ask user to login

        $club = Club::findOrFail($request->input('club'));
        $user = Auth::user();

        if (!$club->managers->contains($user)){
            //tell user your are not manager .

        return $next($request);

But I failed to get the id of club from requests .

How can I solve the problem ?

Thanks in advance .

if you are looking for the url parameters the best way of getting that from the resource routes in laravel 5.2 inside the middleware is below. Lets say you want to get id parameter form url club/edit/{id}

  • 10
Reply Report
      • 2
    • From inspecting the source you can pass the parameter name to the route method and it works the same way, $request->route('id')