我对Laravel非常新。在学习曲线期间,我遇到了一个情况,我将在下面描述:
我的页面包含/ manage-clients路由中的数据网格。对于网格我使用数据表。我为每条记录添加了编辑按钮。现在,我想制作编辑屏幕,这基本上是一个新视图。我希望编辑的url结构为/ manage-clients / edit / {id}。如何通过以下设置实现这一目标。?
下面是我的控制器: public function getIndex()
{
return View('admin.manageclients');
}
public function anyData()
{
$clients = DB::table('users')
->select(['id', 'first_name', 'last_name', 'email', 'created_at', 'updated_at'])
->where('type', '=', '');
return Datatables::of($clients)->addColumn('action', function ($clients) {
return '<a href="edit-client/'.$clients->id.'" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i> Edit</a>';
})->editColumn('id', 'ID: {{$id}}')->make(true);
}
public function editClient($id)
{
//This is my edit function which is going to load the details of provided $id into view.
return $id;
}
我的路线是:
Route::group (array('prefix' => 'admin', 'middleware' => 'auth'), function()
{
Route::get('dashboard',['as'=>'getDashboard', 'uses'=>'Admin\AdminController@getDashBoard']);
Route::controller('manage-admins', 'Admin\ManageAdminController', ['anyData' => 'manage-admins.data','getIndex' => 'manage-admins']);
Route::controller('manage-clients', 'Admin\ManageClientController', ['anyData' => 'manage-clients.data', 'getIndex' => 'manage-clients']);
});
答案 0 :(得分:0)
你的意思是这样吗?
Route::group (array('prefix' => 'admin', 'middleware' => 'auth'), function()
{
Route::get('dashboard',['as'=>'getDashboard', 'uses'=>'Admin\AdminController@getDashBoard']);
Route::controller('manage-admins', 'Admin\ManageAdminController', ['anyData' => 'manage-admins.data','getIndex' => 'manage-admins']);
Route::controller('manage-clients', 'Admin\ManageClientController', ['anyData' => 'manage-clients.data', 'getIndex' => 'manage-clients']);
Route::get('manage-clients/edit/{id}', 'ManageAdminController@editClient');//I have added this code
});
请注意,控制器内部将自动提供ID