Reputation: 703
I am developing a laravel web application of business directory.
here is my scenario.
http://localhost/genie-works/devojp/customer // user searching with keyword of business and
Showing results in http://localhost/genie-works/devojp/customer/search-result?keyword=apple&searchcity=1 this page.
here listing too many business data with post an enquiry feature.
when clicking on the post an enquiry button page goes to http://localhost/genie-works/devojp/customer/post-enquiry/{bisinjessid}/
the post enquiry page checking a middle-ware as authentication.
when user not logged in the middleware redirect to login page http://localhost/genie-works/devojp/customer and showing the login form
after entering login details its needs to redirect to http://localhost/genie-works/devojp/customer/post-enquiry/{bisinjessid}/ this page.
but i tried the function Redirect::back its redirecting to customers page (http://localhost/genie-works/devojp/customer)
How can i solve this issue by redirecting to my last page....
Thanks
Middleware..
public function handle($request, Closure $next)
{
if (!Auth::check()) {
return redirect()->intended(route('cust_index'))->with('activelogin','Succesfully LoggedOut !!!');
}
return $next($request);
}
Controller..
public function custdologin(){
$userdata=array(
'username'=>Input::get('email'), // getting data from form
'password'=>Input::get('password') // getting data from form
);
if(Auth::attempt($userdata)){
switch (Auth::user()->user_type) {
case '2':
return Redirect::to(route('myaccount'));
break;
case '3':
return back();
break;
default:
Auth::logout();
return Redirect::to(route('business_login'))->with('message','Check Your Entries!!');
break;
}
}
else
return Redirect::to(route('business_login'))->with('message','Check Your Entries!!');
}
Upvotes: 1
Views: 186
Reputation: 146191
In your middleware where you are using redirect, use the following:
return redirect()->intended('put a default url'); // i.e: '/dashboard'
This will redirect the user to the intended url (s)he wanted to go without being logged in. Check more here (in Manual Authentication
code snippet)
Upvotes: 1