Laravel User Registration - php

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

Related

First Time User Setup

I'm building a system with users and roles using Jetstream(Livewire)/Fortify auth, but it's a closed system (I mean, there is no way to register yourself, you must be invited) so I disabled Fortify's registration feature, but I want the first user to be able to register himself.
In other words: Fortify's registration should be off, but while there isn't an user in database, it should be on (email validation too, but If I can figure out the registration part, the verification should be easy).
I tried making an middleware to check if there isn't a registered user and redirect to register view, but I found some errors (like the view doesn't even exist 'cause fortify registration is off).
Does someone know a way to make this work using the Jetstream stack? Thanks!
and what about this, in the FortifyServiceProvider.php boot method
Fortify::registerView(function () {
if(!User::all()->count())
return view('auth.register');
else
abort(404,'No registration allowed');
});

Change default landing page of a laravel website

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.

Laravel redirect user to core auth login page when i directly access to guard login page

I have made a multiple login laravel application for which i have used laravel guards and provider concept.Now i am facing an issue which is
Suppose i have a writer user whose route are grouped if i want to direct access any route of the writer users without login then it redirects me to auth login page.
My point is that i want to redirect user to relevant login page if someone direct access to writer user routes it should be redirected to writer user login page instead of auth login page
Thanks in advance
What you need is called Laravel Middlewares. A practical use case for such is the auth middleware, which is applied to prevent anyone who isn't an authenticated user from accessing sensitive pages. Learn more about middlewares Here.

laravel authentication :exact location of AuthController

I am new to the laravel framework,and i setup the laravel basic authentication it simple and awesome.
I need a clarification in following things
1.when i list the all routes using route list command i can see the many routes including the functionalities for login and register ,but the routes not registerd in in route.php file ,how its worked?
2.I want to add some more fields in registration for that i am looking for this function AuthController#register ,but there is no function named register in it,so where it is actually located.??
EDIT
1.I need to find the login functions also,because I want to show custom error message to the user is(password not found,invalid email,account blocked )
2.want to change the route after logout

Laravel 5: when logged in entering URL, Laravel redirects to /home

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.

Categories