【问题标题】:Laravel 5.1 - datatables -Adding a link using editColumnLaravel 5.1 - 数据表 - 使用 editColumn 添加链接
【发布时间】:2015-11-12 20:15:41
【问题描述】:

我正在使用 Laravel 5.1 和数据表 (yajra/laravel-datatables-oracle)。 我想在我的表中添加指向数据的链接,但它不起作用。我想问题是我输入参数的方式,应该不同。

PS:当我删除参数时,它会起作用并显示链接:categorie/afficher

public function anyData()
{
  $categories = \App\Categorie::all();
  return Datatables::of($categories)
           ->editColumn('nom', '<a href="'.route('categorie-afficher', $id).'" >{{$nom}}</a>')
           ->make(true);
}

这是我的路线:

Route::get('/categorie/afficher/{id}', [
    'as' => 'categorie-afficher',
    'uses' => 'CategorieController@afficher'
]);

程序报错:undefined $id。当我输入一个整数值而不是 $id 时,它可以工作!

 ->editColumn('nom', '<a href="'.route('categorie-afficher', 1).'">{{$nom}}</a>')

【问题讨论】:

  • 我认为您在 $id 之后缺少一个冒号)。 " 应该是 $id)。 " '
  • 谢谢,但没有。那不是问题。冒号没问题:)

标签: laravel datatables


【解决方案1】:

generating URLs To Named Routes。在您的情况下,它应该是:

->editColumn('nom', '<a href="{{ route("categorie-afficher",["id"=>$id]) }}" >{{$nom}}</a>')

【讨论】:

  • 谢谢,但它不起作用。它给出[未定义的变量:id]。当我输入一个整数而不是 $id 时它可以工作: ->editColumn('nom', '{{$nom}} a>')
  • @Keyser_Soze 对不起,你是对的。我已经更新了答案。就像在其他刀片视图中一样 - 用 {{ route(...) }} 包装它。
  • 谢谢!这是最终代码: ->editColumn('nom', '{{$nom}}' )
猜你喜欢
  • 2017-04-02
  • 2015-10-13
  • 1970-01-01
  • 1970-01-01
  • 2019-06-23
  • 2018-08-09
  • 1970-01-01
  • 1970-01-01
  • 2015-09-30
相关资源
最近更新 更多