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'];
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With