Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 Illuminate\Database\Eloquent\Model;

class Resource extends Model
{

    protected $table='resource';
    public $fillable=['resname'];
}
like image 284
Nihal Gurjar Avatar asked Dec 06 '16 07:12

Nihal Gurjar


1 Answers

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

like image 136
ssuhat Avatar answered Nov 05 '22 08:11

ssuhat