Laravel retrieve param in class constructor

laravel, laravel-4, php

Solution

If you want to get the parameters in the __construct of your controller you could do this:

class HomeController extends \BaseController
{
    public function __construct()
    {
        $this->routeParamters = Route::current()->parameters();
    }
}

it will return a key value list of parameters for the route (ex: `['companyId' => '1']`) @see \Illuminate\Routing\Route

You can also get a specific parameter using the getParameter() or parameter() methods.

NOTE: I'm not sure this is such a great idea tho. There might be a more elegant way to solve or better approach to your problem.

Problem

Here is my route: ``` Route::controller('/app/{companyId}/', 'HomeController', array('before' => 'auth')); ``` How can I retrieve $companyId argument in __constructor to avoid retrieving it separate in all my actions?

Original source

Related problems