Beforefilter inside the (resource) controller with an instance filter.

Submitted by orlissenberg - 10 years ago

I've put the full namespaces in for science.

# e.g. in the routes
Route::resource('fooresource', 'Some\Thing\FooController');

class FooController extends Controller
{
    public function __construct()
    {
        # the @ makes it look for this function inside the controller instance.
        $this->beforeFilter('@foofunc', ['only' => ['edit', 'delete', 'update']]);
    }
    
    public function foofunc(\Illuminate\Routing\Route $route, \Illuminate\Http\Request $request = null, $value = null)
    {
        dd([$route->parameters(), $request->all(), get_class($value)]);
    }
}