How to Pass Get Parameters to Laravel from with Get Method

How To Pass GET Parameters To Laravel From With GET Method ?

The simplest way is just to accept the incoming request, and pull out the variables you want in the Controller:

Route::get('search', ['as' => 'search', 'uses' => 'SearchController@search']);

and then in SearchController@search:

class SearchController extends BaseController {

public function search()
{
$category = Input::get('category', 'default category');
$term = Input::get('term', false);

// do things with them...
}
}

Usefully, you can set defaults in Input::get() in case nothing is passed to your Controller's action.

As joe_archer says, it's not necessary to put these terms into the URL, and it might be better as a POST (in which case you should update your call to Form::open() and also your search route in routes.php - Input::get() remains the same)

Laravel 5 how to use get parameter from url with controller's sign in method

When you have an URI such as login?r=articles, you can retrieve articles like this:

request()->r

You can also use request()->has('r') to determine if it's present in the URI.

And request()->filled('r') to find out if it's present in the URI and its value is not empty.

Sending POST request with GET parameter in Laravel

Yes you can do as you mentioned in your last route

Route::post('products/{product}/storeOwner', 'ProductController@storeOwner');

And then get the product Id in your functions argument

public function storeOwner (AddProductOwner $request, $productId)
{
dd($productId); // TRY THIS OUT. CHECK THE 2nd ARGUMENT I SET.
$product= Product::find($productId); // PASS THE VERIABLE HERE.
$user = Auth::user();

if ( $user->ownerOf($product)) {
// Check if the current user is already one of the owners).
// If the current user is the owner then return to the product
// This line is not executed because in (products/show.blade.php) we have set a condition.

return redirect('products/' . $request->product);
}

$join = new Join;
$join->role = $request->join_role;
$join->product()->associate($request->product);
$join->user()->associate(Auth::user());

$join->message = $request->message;

$join->save();

// TODO: we have to make this with ajax instead of normal form
return redirect('products/'. $request->product);

}

How to pass post parameters in laravel from the route to the controller?

For post request no need to pass param in url .You will get in request

So route will be

Route::post('/payments', 'Api\PaymentController@apiPaymentByUserId');

and controller method

public function apiPaymentByUserId(Request $request) 
{
$date_from = $request->date_from;
$date_to = $request->date_to;
}

laravel form with get method wrong parameters

finally and after pay many hours the problem resolve according to: this
i just replaced:

RewriteRule ^(.*)$ index.php?/$1 [L]

with:

RewriteRule ^(.*)$ /index.php?/$1 [QSA]

in .htaccess file of host.
thanks for your replies.

laravel - get parameters from http request

Change this:

$router->get('/api/questions/check/(:any)', 'ApiController@getAnswer');

to

$router->get('/api/questions/check', 'ApiController@getAnswer');

And fetch the values with

echo $request->id;
echo $request->choices;

in your controller. There is no need to specify that you will receive parameters, they will all be in $request when you inject Request to your method.

add get parameter to laravel's redirect method

You have to get the parameter in the URL and pass it to redirect method in an array

Route::get('/about/{param}', function () {
return \Redirect::route('/en/about', ['param'=>$param])
});

without having to use named route

Route::get('/about/{param}', function () {
return redirect('/en/about', ['param'=>$param])
});

For optional parameter

Route::get('/about/{param?}', function ($param = 'my param') {
return redirect('/en/about', ['param'=>$param])
});

Laravel request url with parameter problem with GET Method

You can remove the token route parameter:

Route::get('auth/logout', 'UserController.php');

And retrieve the token from the request in the controller:

public function logout(Request $request) {
return response()->json([
'message' => 'Logout Success',
'token' => $request->token
], 200);
}

How can i pass parameter using ? in url in Laravel

I wouldn't define the parameters within the route.

Route::get('test','TestController@test')->name('frontend.test');

I prefer to validate and get the request parameters like this:

use Illuminate\Http\Request;

...

public function test(Request $request)
{
$params = $request->validate([
'id' => 'required|numeric',
'name' => 'required|alpha'
]);

dd($params['id'], $params['name']);
}


Related Topics



Leave a reply



Submit