Reputation: 3071
In laravel 6 I need to run control action with url like :
http://127.0.0.1/ads/showad?wid=207ce8c0-b153-11eb-b997-4d6d53720d0c&subid=
In routes/web.php I have:
Route::get('ads/showad', 'DisplayAdController@showad')->name('show_ad');
I got not found error I tried to modify this url definition as :
Route::get('ads/showad?wid={wid}&subid={subid?}', 'DisplayAdController@showad')->name('show_ad');
and after clearing cache running command :
php artisan route:list
I see in output :
GET|HEAD | ads/showad | show_ad | App\Http\Controllers\DisplayAdController@showad
| GET|HEAD | ads/showad?wid={wid}&subid={subid?} | show_ad | App\Http\Controllers\DisplayAdController@showad |
Anyway I got Not Found error. How have I to modify url defintion to run url, which must be run from external apps?
Thanks!
Upvotes: 1
Views: 609
Reputation: 8340
Your second route is unnecessary.
In your controller you can access to the query parameters like this:
public function showad(Request $request) {
$request->get('wid');
}
you can also use url parameters like this:
Route::get('ads/showad/{wid}/{subid}', 'DisplayAdController@showadById')->name('show_ad_by_id');
In this case you need to do this:
public function showadById($wid, $subid) {
}
Upvotes: 1