Laravel-datatables: Possible to access route parameters query() when running as service?

Created on 27 Apr 2016  路  2Comments  路  Source: yajra/laravel-datatables

Summary of problem or feature request

I'd like to access the parameter of a route /search/{type} within my SearchDataTables classes query and html functions so that I can decide which data to use based on the url selected.

Code snippet of problem

Route::resource('search/{type}', 'General\SearchController');

Then something like:

public function query()
{
    dd($type);
}

System details

  • CentOS 7
  • 5.6.18
  • 5.2
  • v6.10.1
question

Most helpful comment

@laf, this is the approach I use when I want to pass a route variable in my dataTable class.

Controller

public function search($type, TypeDataTable $dataTable)
{
    return $dataTable->forType($type)->render('view.index');
}

DataTable

protected $type;

public function query()
{
    dd($this->type);
}

public function forType($type)
{
    $this->type = $type;

    return $this;
}

All 2 comments

@laf, this is the approach I use when I want to pass a route variable in my dataTable class.

Controller

public function search($type, TypeDataTable $dataTable)
{
    return $dataTable->forType($type)->render('view.index');
}

DataTable

protected $type;

public function query()
{
    dd($this->type);
}

public function forType($type)
{
    $this->type = $type;

    return $this;
}

Thanks so much for the quick response. This worked perfectly :)

Thank you also for such an amazing addition to Laravel and DataTables.

Was this page helpful?
0 / 5 - 0 ratings