Hi, I created raw columns, and I need to pass routes for action buttons. How can I do this?
namespace App\Datatables;
use App\Models\Track;
use Yajra\DataTables\Html\Button;
use Yajra\DataTables\Html\Column;
use Yajra\DataTables\Html\Editor\Editor;
use Yajra\DataTables\Html\Editor\Fields;
use Yajra\DataTables\Services\DataTable;
class TracksDataTable extends DataTable
{
protected $route = "/admin/routes/edit"
public function dataTable($query)
{
return datatables()
->eloquent($query)
// here I need to pass route ($this->route ) for editing or deleting a track
->addColumn('action', 'datatables.actions')
->rawColumns(['action']);
}
public function query(Track $model)
{
return $model->newQuery();
}
// ... other code, that probably not related to that question
MY VIEW FILE ('datatables.actions')
<a href="{{route($route.'.edit', $id)}}">edit</a>
<a href="{{route($route.'.destroy', $id)}}">delete</a>
Use add column with closure: https://yajrabox.com/docs/laravel-datatables/master/add-column#closure
Route::get('user-data', function() {
$model = App\User::query();
return DataTables::eloquent($model)
->addColumn('intro', function(User $user) {
$route = $this->route;
return view('datatables.action', compact('route', 'user'));
})
->toJson();
});
thank you very much it s what i was searching for
Most helpful comment
Use add column with closure: https://yajrabox.com/docs/laravel-datatables/master/add-column#closure