Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel get query string

Tags:

php

laravel

I have the following url http://project.su/?invitee=95

first i want to check the invitee in url, if the url have invitee then get the value.

What i have tried (controller) :

if(!empty($request->get('invitee'))){
   $user->invitee = $request->get('invitee');
}

The following code is not working .

I want storing the invitee result(id) in database.

Thanks.

like image 609
Gammer Avatar asked Aug 03 '16 07:08

Gammer


People also ask

How do I get params in laravel?

Laravel routes are located in the app/Http/routes. For instance, to pass in a name parameter to a route, it would look like this. Route::get('/params/{name}', function ($name) { return $name }); By convention, the Controller function accepts parameters based on the parameters provided.

How can pass query string in URL in laravel?

You can pass query string to URL in laravel using named route and controller action. You can pass query string as comma separated array to named route and controller action and redirect to URL.

How do you get query string in laravel blade?

You can check query string exists or not in laravel blade with comparing the value with null. If query string is not exists in URL then it will return true while using comparision (=) operator.

How do I print a query in laravel 8?

Using laravel query log we can print the entire query with params as well. In this type of debugging query is executed and we will get the complete parsed query. Here we used DB::enableQueryLog to enable the query log and DB::getQueryLog() to print the all queries in between of it.


2 Answers

To determine if an input value is present:

if ($request->has('invitee')) {
   $user->invitee = $request->input('invitee');
}

The has method returns true if the value is present and is not an empty string:

like image 188
Depzor Avatar answered Oct 22 '22 16:10

Depzor


As far as Laravel 5.7 is concerned, the preferred way to retrieve query params is

if( $request->has('invitee') ) {
    $request->query('invitee');
}

or using the helper function if you don't have access to $request

request()->query('invitee');
like image 16
Vikram Bhaskaran Avatar answered Oct 22 '22 14:10

Vikram Bhaskaran