Home » Php » php – laravel 5.2 : Get query string

php – laravel 5.2 : Get query string

Posted by: admin July 12, 2020 Leave a comment


I have the following url

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

What i have tried (controller) :

   $user->invitee = $request->get('invitee');

The following code is not working .

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


How to&Answers:

To determining 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:


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

if($request->has('invitee') {

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



You can get input by:

$invitee = Input::get('invitee');

For above 5.*

$invitee = $request->input('invitee');


$invitee = Request::input('invitee');


In laravel 5.7, we can also use request()->invitee. By using this, we can get both, URL path parameters and query parameters. Say we have below URL


To read id and invitee, we can use

$id  ✔
$invitee ✖ - Invalid
request()->id ✔
request()->invitee ✔


Are you calling $user->save() anywhere? You should call $user->save() to actually persist the data.

You can always check by calling dd($user); right after the second line in you example if you are worried it is not set correctly, this way you can see what attributes are set in the $user object.

Also you can replace !empty($request->get('invitee')) with $request->has('invitee').


To check if invitee parameter exists:

if($request->has('invitee')) {
    // ...

To get the value of invitee:

$invitee = $request->input('invitee');