hkguile hkguile - 10 months ago 100
PHP Question

laravel 5.2 return datatables and assign db field value before passing to blade

i have a function will return a datatables json, but the $type need to be set before passing to blade. I want to assign the each row result 'type' to $type, how can i do that? It needs to assign first so the blade can translate the value.

public function data() {

$vendor_id = $this->getVendorId ();

$menu = Menu::with('meal')->find($vendor_id);
$meal = $menu->meal;

return Datatables::of($meal)
-> edit_column('type', '{{trans(\'admin/meal.'.$type.'\')}}')
//-> edit_column('type', '<a href="#" >'.trans('admin/meal.' . $type).'</a>')
-> edit_column('name', '<a href="{{{ URL::to(\'admin/project/\' . $id ) }}}" >{{$name}}</a>')
-> add_column('actions', '<a href="{{{ URL::to(\'admin/meal/\' . $id . \'/edit\' ) }}}" class="btn btn-success btn-sm iframe" ><span class="glyphicon glyphicon-pencil"></span> {{ Lang::get("admin/modal.edit") }}</a>
<a href="{{{ URL::to(\'admin/meal/\' . $id . \'/delete\' ) }}}" class="btn btn-sm btn-danger iframe"><span class="glyphicon glyphicon-trash"></span> {{ Lang::get("admin/modal.delete") }}</a>
<input type="hidden" name="row" value="{{$id}}" id="row">')

-> remove_column('id')
-> remove_column('created_at')
-> remove_column('vendor_id')
-> make();



The trans() function, is a helper function that can be called in the class herself, something like:

public function data() {


return Datatables::of($meal)
->editColumn('type', function($item) {
            return trans('admin/meal.'.$item->type); 

I do know if is that what you mean.