Home > database >  determine url parameter in Laravel
determine url parameter in Laravel

Time:03-08

I am new to Laravel an have a question. I have controller named ReportsArchiveController and function named loadReport in it. this is what the method get

public static function loadReport(Request $request, $id, $view = 'reports.archive.single', $user_id = null)

this is the rout:

Route::get('/archive/{id}', ['as' => 'reports.archive.view', 'uses' => 'ReportsArchiveController@loadReport']);

I want to create new route that will use this method, and ask from where the user entered.

Route::get('/archive/{id}/csv', ['as' => 'reports.archive.view', 'uses' => 'ReportsArchiveController@loadReport']);

and ask in the method load report if the url is from /archive/{id}/csv or from /archive/{id}.

what I should add to the loadreport method to know if the user is from the url with csv or without? what to add to the method parameters? using Laravel 7

CodePudding user response:

You can get url from request and check it

script

$request->url();

For more information: https://laravel.com/docs/7.x/requests#request-path-and-method

  • Related