Request get method route handling - laravel

I am using laravel 5 . I want to set route like
http://localhost:8000/website/product-search-data?term=k
I also tried with
Route::get('/website/product-search-data/*', 'websiteController#searchProductList');
public function searchProductList($term)
{
dd($term);
}
But its providing me Sorry, the page you are looking for could not be found. How can I handle and get parameer value ?

Maybe can try this instead:
Route::get('/website/product-search-data/{term}', 'websiteController#searchProductList');
public function searchProductList($term) {
dd($term);
}

Related

Laravel: Missing Argument error on a POST

I keep getting the error "Missing argument 1 for App\Http\Controllers\Users::deleteMobileAssets()" . I am making a call from my frontend with Vue. When I check the headers, it seems correct but I'm not sure what is causing the error. I've tried wrapping imageType in brackets too: {imageType: imageType} but still same error.
deleteImage(imageType) {
axios.post('/delete-mobile-assets', imageType);
}
public function deleteMobileAssets($imageType)
{
}
POST data is included in the body of the request that way you are getting Missing argument 1. Try this
deleteImage(imageType) {
axios.post('/delete-mobile-assets', {imageType:imageType});
}
public function deleteMobileAssets(Request $request)
{
$request->imageType
}
Or if you want to implement DELETE method. have a look Delete Method in Axios, Laravel and VueJS

How to get the second argument from route in laravel

I am trying to get the second argument from the route in laravel from the following code.
web.php
Route::get('users/{name}/forksnippets/{name2}','Forksnippet#viewforksnippet');
controller
public function viewforksnippet($slug){
dd($slug);
}
getting name here as result
Just add the second argument to the method of the controller.
public function viewforksnippet($slug, $name2)
{
dd($slug, $name2);
}
public function viewforksnippet($name, $name2)
{
dd($name2);
}
Please try this ex

Laravel 5.7 ApiResource GET params empty

I use Laravel 5.7 for my JSON API web application.
In my routes/api.php file, I created the following route :
Route::apiResource('my_resource', 'API\Resource')->except(['delete']);
I added the corresponding controller and methods (index, show,...) and everythink work perfectly. My issue is the following : I would like to add optional GET params like this :
http://a.x.y.z/my_resource?param=hello&param2=...
And for instance being able to retrieve 'hello' in my index() method. However, when I print the value of $request->input('param'), it's empty. I just don't get anything.
Yet, if I create a route like this, with an optional parameter:
Route::get('/my_resource/{param?}', 'API\Resource');
I'm able to get the parameter value in my controller method.
Here is my index method :
class Resource extends Controller {
public function index(Request $request)
{
print($request->input('param'));
// ...
}
// ...
}
Am I missing something ? I'm still new in Laravel maybe I missed something in the documentation.
Thanking you in advance,
You can use:
$request->route("param");

Dynamic Routes not found

I am having trouble getting dynamic routes to work in Laravel 4
Routes
Route::any('/browse/{$id}', 'BrowseController#showProfile');
Controller
<?php
class BrowseController extends BaseController {
public function showProfile($id)
{
return $car_id;
}
}
When I go to http://localhost:8000/browse/10018
I receive a not found error
Any Idea what is wrong? Sorry I am new to Laravel
You don't need a $ in the variable name in your route. Try using
Route::any('/browse/{id}', 'BrowseController#showProfile');
Also, you should add validation to only allow numbers:
Route::any('/browse/{id}', 'BrowseController#showProfile')->where('id', '\d+');
The problem is in {$id}, try only {id}

Laravel 4: get url parameter from controller

I'm new to laravel 4 and I'm currently having the following problem:
In my routes.php I have the line:
Route::get('maps/{map_type}', 'MapsController#loadMaps');
And in my MapsController I'd like to get the {map_type} to use it.
So my question: How can I retrieve map_type in my Controller?
Your first argument in your loadMaps method is your map type.
public function loadMaps($map_type) {
return $map_type;
}
Take a look at the first two code snippets on http://laravel.com/docs/controllers.
Controllers receive parameters as parameters in the called function:
class MapsController extends BaseController {
public function loadMaps($map_type) {}
}
Check http://laravel.com/docs/controllers#basic-controllers for more info

Resources