Laravel display the query parameter in the url

Viewed 271

I have users table and each user have a column for 'qr_url' and it's a random 170 characters length string generated with Str::random I have a page that displays all the users and for each user there is a button named inquiry to check if the user exists in the database I have a route name inquiry that check if this qr_url already for a user or not

Route::get('/users/inquiry/{query}', [UserController::class, 'inquiry'])->name('users.inquiry');

in the inquiry() function I receive this query that contain the qr_url

public function inquiry($query)
{
    $user = User::where('qr_url', '=', $query)->first();

    return view('users/inquiry', compact('user'));
}

I need to know how can I make the URL looks like that

http://example.com/Home/GetResultByQR?query=theqr_url
1 Answers

Hello guy you should use request()->get('query'). For example:

public function inquiry()
{
    $user = User::where('qr_url', '=', request()->get('query'))->first();

    return view('users/inquiry', compact('user'));
}
Related