I am using Language switch to switch between English and Arabic. It is working fine in all the links except Home page.
If I have not authenticated it is working fine it is redirecting to http://domain.name/en/login
If I have authenticated or logged in and try to access the url http://domain.name/ it is redirecting to http://domain.name/home instead of a http://domain.name/en/home
I have changed in all the Auth files by adding a function:
public function redirectTo(){
return app()->getLocale().'/home';
}
The solution for this is to make a automatic redirect to the page.
Route::get('/home', function () {
return redirect(app()->getLocale());
});
Related
I wanna set localization in middleware, like if user is not authed redirect to login,
redirect works but next language is not changing like if current lang set as fr after redirecting it changes as en
here is code what I've tried App:setLocale() not effected
/Authenticate.php
protected function redirectTo($request)
{
if (! $request->expectsJson()) {
App::setLocale('fr'); // I want to implement something like that, for all auth urls
return route('login','fr');
}
}
Can someone help, how to change login,register ... language with current lang.
Route returns and redirect to it does not occur
return redirect()->guest(route('login','fr'));
I try writting the url http://127.0.0.1:8000/home and I'm not logged in and it shows me home page but obviously not loaded correctly, What I want is when I write http://127.0.0.1:8000/home to redirect me to http://127.0.0.1:8000/login page I know this works in fresh projects with make:auth module, I don't know why stopped workin.
In my home I have this
public function __construct()
{
$this->middleware('auth');
}
and my routes file:
Route::get('/', function () {
return view('auth\login');
});
Auth::routes();
Route::post('create','IngresarSolicitud#store');
Route::get('/home','IngresarSolicitud#informacionempleado');
I added ->middleware('auth'); at the end of my routes to redirect to login in this case, thanks
without login If I give any URL's in the admin panel it is opening. How to solve it?
while login I am using,
$request->session()->put('userId', $user->userId);
In logout I am using,
$request->session()->forget('userId');
Route file,
Route::get('/addModule', function () {
return view('addModule');
});
How can I redirect to login screen. while am calling any admin panel URL's.
Just write this code in routes.php
Route::get('logout', function(Request $request) {
Auth::logout();
return redirect('/login');
});
Remember to import Auth class
I am on page : http://laravel.dev/lists
which shows me list of item
Item 1
Item 1
Item 1
but above item can only accessible to authorized user
Issue
when i click on Item 1 so if user is not logged in then it goes to http://laravel.dev/login then user proceed to login but after login it must redirect to http://laravel.dev/lists/1 but it is redirecting to http://laravel.dev/home.
I have tried
public function showLoginForm()
{
session()->put('url.intended',url()->previous());
// or
session()->put('url.intended', url()->current());
return view('user.auth.login');
}
but above is not working, it is redirecting to http://laravel.dev/lists
laravel own auth is working fine.
but hesto multi-auth is not working
I am using this Hesto-multi-auth package for multiple authentication like admin, user, employee
is there any solution for this
If you're using the default user Authentication system in Laravel, and if you added auth middleware in your routes, it's automatically done by Laravel.
In your routes:
Route::group(['middleware' => 'auth'], function() {
. . . Your Routes goes Here
});
You can take a look at the docs https://laravel.com/docs/5.4/authentication#protecting-routes
You can use middleware. For example :
Route::get('lists/{id}', function () {
//
})->middleware('auth');
Please refer here : https://laravel.com/docs/5.5/middleware for more information
First of all find the place where you redirect unauthenticated user to the login page (probably in app/Exceptions/Handler.php function unauthenticated) and save to the session current url ("/lists/1") before redirect.
Afrer that add in your Auth controller property $redirectTo and fill it from the session or define method redirectTo (method also nust return url).
Out of the box laravel redirects to /home because of trait /Illuminate/Foundation/Auth/RedirectsUsers.
You can try this idea: After you've successfully logged in, you'll be redirected to the page you want (e.g. http://laravel.dev/lists/1)
Auth::attempt(...);
return redirect()->route('the name of your route here where redirected to http://laravel.dev/lists/1');
What you had tried in the showLoginForm() won't be work, because neither url()->previous() nor url()->current() you specified were not the url you want.
Solution:
Changed in the middleware:
public function handle($request, Closure $next, $guard = 'user')
{
if (!Auth::guard($guard)->check()) {
session()->put('url.intended', \URL::current()); // Add this line
return redirect('user/login');
}
return $next($request);
}
I'm using a controlled route as such
Route::controller('company', 'CompanyController');
In this Controller i have a getLogin and postLogin function, the getLogin shows the login view. To get there i need to go to company/login
Now i'm wondering how can i redirect company/ to company/login
I have the following working but is it good practice?
Route::get('company', 'CompanyController#getLogin');
Route::controller('company', 'CompanyController');
Thank you!
In this case, index methods will respond to the root URI, so what you can do is create a getIndex() function which will return Redirect::to('company/login'). You can probably do a check on this for a logged in user first as well, for example...
public function getIndex()
{
if(!Auth::check())
return Redirect::to('company/login');
// Continue with what should happen if the user is logged in.
}
This way, when someone goes to /company, it will redirect them to login if they aren't logged in already or it will continue doing whatever you want it to do or redirect them to the same page you are redirecting people to after they login.
This also means you can do away with that Route::get() that you have setup for company.