gpt4 book ai didi

php - RouteCollection.php 中的 NotFoundHttpException 第 161 行 : laravel 5. 3

转载 作者:可可西里 更新时间:2023-11-01 12:56:30 25 4
gpt4 key购买 nike

在 laravel 中,我试图链接到一个特定的页面,但它正在显示

NotFoundHttpException in RouteCollection.php line 161:

这是我的代码,请帮我找出错误
在我看来:

{{ link_to_route('deleteFile', 'Delete', [$file->resid]) }}  

在 route :

Route::get('/deleteFile/{$id}',
['as'=>'deleteFile','uses'=>'FilesController@deleteFile']);

在 Controller 中:

  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');
}}

这是我的模型代码:

namespace App;

use Illuminate\Database\Eloquent\Model;

class Resource extends Model
{

protected $table='resource';
public $fillable=['resname'];
}

最佳答案

你的参数有误。它应该是 {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');

链接:https://laravel.com/docs/5.3/routing#named-routes

关于php - RouteCollection.php 中的 NotFoundHttpException 第 161 行 : laravel 5. 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40989963/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com