在laravel我试图链接到特定页面,但它正在显示
RouteCollection.php第161行中的NotFoundHttpException:
这是我的代码,请帮我弄清楚错误 在我看来:
public void setAsUsed(used = true);
public void setAsNotUsed(used = false);
路线中的:
{{ link_to_route('deleteFile', 'Delete', [$file->resid]) }}
并在控制器中:
Route::get('/deleteFile/{$id}',
['as'=>'deleteFile','uses'=>'FilesController@deleteFile']);
这是我的型号代码:
class FilesController extends Controller{
public function deleteFile($id)
{
$file = Resource::find($id);
Storage::delete(config('app.fileDestinationPath').'/'.$file->filename);
$file->delete();
return redirect()->to('/upload');
}}
答案 0 :(得分:4)
{id}
而不是{$id}
更改
Route::get('/deleteFile/{$id}',
['as'=>'deleteFile','uses'=>'FilesController@deleteFile']);
到
Route::get('/deleteFile/{id}',
['as'=>'deleteFile','uses'=>'FilesController@deleteFile']);
链接:https://laravel.com/docs/5.3/routing#required-parameters
和Laravel 5.3现在支持使用name
Route::get('/deleteFile/{id}','FilesController@deleteFile')->name('deleteFile');
答案 1 :(得分:0)
好像你的控制器文件中有一个`字符
class FilesController extends Controller{
public function deleteFile($id)//it was right here
{
$file = Resource::find($id);
Storage::delete(config('app.fileDestinationPath').'/'.$file->filename);
$file->delete();
return redirect()->to('/upload');
}
}
试试这个