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.
// only query
$query_array = $request->query();
or
$query = $request->query('r');
// Without Query String...
$url = $request->url();
// With Query String...
$url = $request->fullUrl();
If you are using Laravel then use their helper which works just out of the box, i.e. if your route or url has a auth middlewere and user is not logged in then it goes to login and in your postSign or inside attempt just
return redirect()->intended('home'); //home is the fallback if no intended url is provide
UserController
public function postSignIn(Request $request){
$this->validate($request, [
'login-email' => 'required|email',
'login-password' => 'required'
]);
if ( Auth::attempt(['email' => $request['login-email'], 'password' => $request['login-password']]) )
{
return redirect()->intended('user.account);
}
return redirect()->back();
}