Laravel Yajra数据表if addColumn上的语句

时间:2016-09-21 14:00:27

标签: php laravel

我一直坚持在if声明中添加addColumn声明:

$inquiries = Inquiry::with('customer')->get();

return Datatables::of($inquiries)
    ->editColumn('created_at', function ($inquiry) {
        return $inquiry->created_at->format('d-m-Y');
    })
    ->editColumn('due_date', function ($inquiry) {
        return Carbon::parse($inquiry->due_date)->format('d-m-Y');
    })
    ->editColumn('status', '@if($status == 0) Pending @elseif($status == 1) Accept @else Cancel @endif')
    ->addColumn('action', function ($inquiry) {
        return '
        <a href="/inquiries/' . $inquiry->id . '" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i> View</a>
        <a href="/inquiries/' . $inquiry->id . '/edit" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i> Edit</a>
        <a href="#" id="delete-button" data-id="' . $inquiry->id . '" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i> Delete</a>
        ';
    })
    ->make(true);

我试图放@if @endif,但它似乎打印出来而不是成为一个功能

我想根据状态显示操作按钮。

任何解决方案?

由于

2 个答案:

答案 0 :(得分:0)

你可以做以下的事情吗?

->editColumn('status', function ($inquiry) {
    if ($inquiry->status == 0) return 'Pending';
    if ($inquiry->status == 1) return 'Accept';
    return 'Cancel';
})

答案 1 :(得分:-1)

return Datatables::of($data)->addColumn('action' , function($data){
    $x='';
    if($data->is_public==0){
        $x.='  <button class="btn btn-inof btn-success">visible</button>';
    }if ($data->is_public==1) {
        $x.='  <button class="btn btn-inof btn-danger**strong text**"> not visible</button>';
    }
     return '
       <button class="btn btn-sm btn-circle btn-danger" 
        id="category_delete_btn" onClick="delete_category('.$data- 
          >id.')"><span class="fa fa-trash "></span></button>

       '.$x.'
     ';
})->make(true);