NotFoundHttpException in RouteCollection.php line 161: laravel 5.3

In laravel i am trying to link to a particular page but it is showing

NotFoundHttpException in RouteCollection.php line 161:

Here is my code please help me figure out the mistake
in my view :

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

in routes :

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

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

and this is my model code :

namespace App;

use IlluminateDatabaseEloquentModel;

class Resource extends Model
{

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

You make mistake on your params. it should {id} not {$id}

Change

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

to

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

Link: https://laravel.com/docs/5.3/routing#required-parameters

and Laravel 5.3 now support using name

 Route::get('/deleteFile/{id}','FilesController@deleteFile')->name('deleteFile');

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


It seems like you had a ` character in your controller file

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

Try this

链接地址: http://www.djcxy.com/p/94188.html

上一篇: 使用window.location.search跨站点脚本问题

下一篇: RouteCollection.php中的NotFoundHttpException行161:laravel 5.3