在laravel我试图链接到一个特定的页面,但它正在显示
NotFoundHttpException in RouteCollection.PHP line 161:
{{ 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'); }}
这是我的型号代码:
namespace App; use Illuminate\Database\Eloquent\Model; class Resource extends Model { protected $table='resource'; public $fillable=['resname']; }
你在你的参数上犯了错误.应该{id}不是{$id}
原文链接:https://www.f2er.com/laravel/134319.html更改
Route::get('/deleteFile/{$id}','uses'=>'FilesController@deleteFile']);
至
Route::get('/deleteFile/{id}','uses'=>'FilesController@deleteFile']);
链接:https://laravel.com/docs/5.3/routing#required-parameters
Route::get('/deleteFile/{id}','FilesController@deleteFile')->name('deleteFile');