I know i is a very common question, but i am purely new to laravel and i know very little about laravel thats's why i am asking it.
So point is that when a user enters http://dytube.cric4fun.com/ he must be automatically redirected to the http://dytube.cric4fun.com/login
So, how i do this, in past in simple non-laravel based we used .htaccess and in laravel how we will do it.
You can change your home directory route in web.php file like this:
Route::get('/', function(){
return redirect()->route('login');
});
This way, if the user is logged in, he/she will be automatically redirected to home page and anywhere you have chosen for redirection after successful login.
Related
I used php artisan make:auth in my laravel project to automatically create my login and registration pages.
Even though I'm still logged in when I leave my page for a few minutes and then go back to my laravel project page it redirects to the login page.
I know i'm logged in because I can see it on the upper part of the login page if user wasn't logged in it would display two buttons login and register and if user was already logged in it would just display my username which it did and also the fact that I can go to my dashboard page by just manually typing it in the url which shouldn't be allowed if user wasn't logged in :(
How can I fix this?
Assuming that you have a route of your dashboard
Route::route('/home', 'HomeController#index')->middleware('auth');
You just need to use auth middleware in order to add page visits restrictions.
You may check more authentication detail here https://laravel.com/docs/5.8/authentication
I've made a CMS, in Laravel, for a local charity, as part of my final research project. I have to present it in the morning and I have one niggling problem, that I can't figure out.
I have posts and comments, users and admins. Any authenticated user-type can comment on a post. I have a modal, for logging in, on the single post page and this is just a simple #if statement, that replaces the button.
If I login as an admin, I'm redirected to the admin panel, which is what I wanted. If I login as a user, i'm redirected to home; not good. I simply want to redirect a user using return back()->withInput I cannot seem to find the right class that deals with a user's redirect. I have tried in the login controller and the redirectIfAuthenticated middleware and neither works.
I'm tired, it's 4am and I'm probably looking in the wrong files. A little help would be great though, thank you.
the simplest solution is to define an authenticated method inside your AuthController and put the logic there:
protected function authenticated($request, $user)
{
if($user->role === 'admin') {
return redirect()->intended('/admin_path_here');
}
return redirect()->intended('/path_for_normal_user');
}
In laravel, now I hope to know this problem.
I try to reset password in logout status and the problem is it's redirect automatically to dashboard page if I logged in already.
So I hope to know how to logout and goes to special url such as reset password url from my received mail.
Please help me!
Use Laravel Auth vendor. https://laravel.com/docs/5.1/authentication. After this in route file put all routes under authentication where you want user to be logged in.
For laravel 5+ :
create a middleware for your route and check your access condition in this middleware, if your route passes the condition then it will show your desired page.
I'm looking for a way for users that are logged in to register new users. I don't want unregistered users creating new users. The problem that I'm coming up against is that Laravel does a lot of rerouting when you use their registration controllers so that it auto reroutes you away from the registration page if you are already logged in. Is there a way that I can get around this functionality without having to rewrite all of the registration logic?
I've tried simply adding auth middleware to the registration route but it immediately reroutes to the home page of the app before you hit the registration view. If I create a route that redirects to the registration view like this-
Route::get('register', function(){
return view('auth.register');
});
It will give me the registration page but silently fail to add any users to the database. I think it may be because the RegistersUsers class has use RedirectsUsers as its first statement. Short of rewriting the code there is there another way to accomplish what I'm trying to do?
I'm using Laravel 5.2 with the make:auth standard views
I am building login functionality (rather say using it) and when I enter manualy
Route::get('/offers', 'OfferController#index'), I get redirected to /home.
Before login functionality my route was working just normal.
How could I solve this?
The reason you're getting the redirect is because you are using guest middleware on /offers route.
The purpose of the guest middleware (which uses RedirectIfAuthenticated class) is to redirect authenticated users out from pages that should be accessible only for guests, e.g. login form or registration page. Hence the middleware name guest. The middleware checks if user is authenticated and redirects authenticated users to /home which is exactly what you are experiencing.
You can see the code of the middleware here: https://github.com/laravel/laravel/blob/master/app/Http/Middleware/RedirectIfAuthenticated.php. The whole logic happens in its handle() method.