Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

RabbitSC2's avatar

Whats wrong with my routes.php file?

Hi guys, new here, and also new to Laravel, and must say im loving it so far!

I have a site im working on, that has 2 registration forms, for 2 different users. Its basically the same form just with a hidden value (either 0 or 1) that is different, along with the overall look of the page. Mechanically its exactly the same as the other form.

I have setup my routes.php file as such :

Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');
Route::get('auth/performer-registration', 'Auth\AuthController@getRegister');
Route::post('auth/performer-registration', 'Auth\AuthController@postRegister');

I have 2 files within resources\views\auth :

register.blade.php
performer-registration.blade.php

When i goto /auth/register i get the registration form, when i goto /auth/performer-registration i get the same form....

Its like register and performer-registration both show the same page (~in fact they do!). Im not sure where im going wrong!

Any suggestions would be great.

Thanks in advance, Eddy

0 likes
28 replies
zachleigh's avatar

Both routes use the same controller method and likely return the same view. That they act exactly the same is expected. If you want them to be different, send the get requests to different controller methods and return different views with different forms.

Snapey's avatar

please edit your question and put three back ticks ` before and after.

From what I can see, both routes call the getRegister method. How did you expect to serve up the performer form?

create a getPerformerRegister method and then call that.

RabbitSC2's avatar

Thanks for the responses guys, really appreciated!

Im really new to this, so go easy...

With creating a new method ie. getPerformerRegister, where would i add that? Into AuthController?

Thanks again!

zachleigh's avatar

Yes. You would make a getPerformerRegister method in the AuthController and then change the line in routes to look like this:

Route::get('auth/performer-registration', 'Auth\AuthController@getPerformerRegister');

You would maybe have to change the post route too to make sure the additional field is saved, but Im not sure. Try it to see if it works first.

RabbitSC2's avatar

Hmm might sound stupid, and new but how do i create a new method?

zachleigh's avatar

Go to the AuthController and make one.

public function getPerformerRegister()
{
    return view('my.view');
} 
RabbitSC2's avatar
public function getPerformerRegister (array $data)
    {
            $this->redirectTo = '/auth/welcome';
            Mail::send('email.password', $data, function($message) use ($data)
            {
                $message->to($data['email'], $data['name'])->subject('Welcome to Models Allowed');
            });
            $secretpass = str_random(8);
            return User::create([
            'name' => $data['name'],
            'username' => $data['username'],
            'email' => $data['email'],
            'role' => $data['role'],
            'secretpass' => $secretpass,
            'password' => bcrypt($data['password']),
            ]);
            
        }

Returns this error :

ReflectionException in Route.php line 280:
Method App\Http\Controllers\Auth\AuthController::getPerformerRegister () does not exist

PS > Thanks for the help!

RabbitSC2's avatar
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

Route::get('/', function () {
    return view('home');
});

Route::get('/auth/welcome', function () {
    return view('auth/welcome');
});

Route::get('/dashboard', function () {
    return view('dashboard/user');
});

Route::get('/about', function () {
    return view('information/about');
});

Route::get('/terms', function () {
    return view('information/terms');
});

Route::get('/privacy', function () {
    return view('information/privacy');
});

Route::get('/cookies', function () {
    return view('information/cookies');
});

Route::get('/contact', function () {
    return view('information/contact');
});


// Authentication routes...
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@logout');

// Registration routes...
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');
Route::get('auth/performer-registration', 'Auth\AuthController@getPerformerRegister ');
Route::post('auth/performer-registration', 'Auth\AuthController@postPerformerRegister ');

Route::controllers([
   'password' => 'Auth\PasswordController',
]);
zachleigh's avatar

You have a space after getPerformerRegister and postPerformerRegister in the routes file.

Youre probably going to run into another error as well. You are type hinting array in your controller method but you will be receiving a Request object. That will probably throw an error.

RabbitSC2's avatar
ErrorException in AuthController.php line 89:
Argument 1 passed to App\Http\Controllers\Auth\AuthController::getPerformerRegister() must be of the type array, none given

Yep...unfortunately that means nothing to me! Where do i start?

Thanks again for your help!

zachleigh's avatar

Yeah, you are type hinting array as a required parameter but there is nothing being sent.

public function getPerformerRegister ()
{
            
}

This method should only be getting a view for the user, not registering the user. Do that in the postPerformerRegister method.

RabbitSC2's avatar

Ok i think i understand the problem...

So i done this :

public function getPerformerRegister()
        {
            return view('auth.performer-registration');
        } 
        
        public function postPerformerRegister(array $data)
        {
                $this->redirectTo = '/welcome';
                Mail::send('email.password', $data, function($message) use ($data)
                {
                    $message->to($data['email'], $data['name'])->subject('Welcome to Models Allowed');
                });
                $secretpass = str_random(8);
                return User::create([
                'name' => $data['name'],
                'username' => $data['username'],
                'email' => $data['email'],
                'role' => $data['role'],
                'secretpass' => $secretpass,
                'password' => bcrypt($data['password']),
                ]);
                
            }

And now i get this error :

Argument 1 passed to App\Http\Controllers\Auth\AuthController::postPerformerRegister() must be of the type array, none given

But arent i creating an array here...?

public function postPerformerRegister(array $data)
zachleigh's avatar

No, in the get method, you are type hinting an array and demanding an array, but nothing is being passed to this method. The get method should only be returning a view.

RabbitSC2's avatar

What is type hinting? :-\

Im so confused...lol

Isnt this just getting a view though?

public function getPerformerRegister()
        {
            return view('auth.performer-registration');
        } 
zachleigh's avatar

Yes. That is what you want to do. You are getting the view that contains the form.

Type hinting is where you declare the type of the parameters passed to a method. It means that the parameters must be of the declared type.

RabbitSC2's avatar
public function postPerformerRegister(array $data)
        {
                $this->redirectTo = '/welcome';
                Mail::send('email.password', $data, function($message) use ($data)
                {
                    $message->to($data['email'], $data['name'])->subject('Welcome to Models Allowed');
                });
                $secretpass = str_random(8);
                return User::create([
                'name' => $data['name'],
                'username' => $data['username'],
                'email' => $data['email'],
                'role' => $data['role'],
                'secretpass' => $secretpass,
                'password' => bcrypt($data['password']),
                ]);
                
            }

Isnt this then, just reusing the array previously created from here :

protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => 'required|max:255',
            'username' => 'required|unique:users',
            'email' => 'required|email|max:255|unique:users',
            'role' => 'required|max:255',
            'password' => 'required|min:6|confirmed',
        ]);
    }
zachleigh's avatar

The 'array' (its actually a request object) is created when the user fills in the form on the website. The validate method doesn't create amything, it just validates the user supplied input.

RabbitSC2's avatar

So where in here is the data stored to be used?

 /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => 'required|max:255',
            'username' => 'required|unique:users',
            'email' => 'required|email|max:255|unique:users',
            'role' => 'required|max:255',
            'password' => 'required|min:6|confirmed',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {
            $this->redirectTo = '/welcome';
            Mail::send('email.password', $data, function($message) use ($data)
            {
                $message->to($data['email'], $data['name'])->subject('Welcome to Models Allowed');
            });
            $secretpass = str_random(8);
            return User::create([
            'name' => $data['name'],
            'username' => $data['username'],
            'email' => $data['email'],
            'role' => $data['role'],
            'secretpass' => $secretpass,
            'password' => bcrypt($data['password']),
            ]);
            
        }

Thats what was originally in my authController

Im just confused as to where/how the data comes from the form, to the database...

RabbitSC2's avatar

Im just genuinely stumped as to what im meant to be doing here....lol

Am i meant to edit the trait file?

zachleigh's avatar

No. The AuthController uses the trait. You shouldn't edit the trait, just put your methods in the AuthController.

RabbitSC2's avatar

I still dont understand.

protected function create(array $data)
    {
            $this->redirectTo = '/welcome';
            Mail::send('email.password', $data, function($message) use ($data)
            {
                $message->to($data['email'], $data['name'])->subject('Welcome to Models Allowed');
            });
            $secretpass = str_random(8);
            return User::create([
            'name' => $data['name'],
            'username' => $data['username'],
            'email' => $data['email'],
            'role' => $data['role'],
            'secretpass' => $secretpass,
            'password' => bcrypt($data['password']),
            ]);
            
        }

Works fine, but...

public function postPerformerRegister(array $data)
        {
                $this->redirectTo = '/welcome';
                Mail::send('email.password', $data, function($message) use ($data)
                {
                    $message->to($data['email'], $data['name'])->subject('Welcome to Models Allowed');
                });
                
                return User::create([
                'name' => $data['name'],
                'username' => $data['username'],
                'email' => $data['email'],
                'role' => $data['role'],
                'password' => bcrypt($data['password']),
                ]);
                
            }

Doesnt work? Although its basically a direct copy?

RabbitSC2's avatar

OK! Progress...

So i've managed to get the form to work by doing this :

public function postPerformerRegister(Request $request)
        {
                $data = $request->all();
            
                $this->redirectTo = '/welcome';
                Mail::send('email.password', $data, function($message) use ($data)
                {
                    $message->to($data['email'], $data['name'])->subject('Welcome to Models Allowed');
                });
                
                return User::create([
                'name' => $data['name'],
                'username' => $data['username'],
                'email' => $data['email'],
                'role' => $data['role'],
                'password' => bcrypt($data['password']),
                ]);
                
            }

This posts the data to the database, and allows the user to login. but rather than returning to /welcome it actually just shows the posted information on a blank page!

zachleigh's avatar
Level 47

Thats because you are returning the User object. Try this:

public function postPerformerRegister(Request $request)
{
    $data = $request->all();
            
    $this->redirectTo = '/welcome';

    Mail::send('email.password', $data, function($message) use ($data) {
        $message->to($data['email'], $data['name'])->subject('Welcome to Models Allowed');
    });
                
    $user = User::create([
        'name' => $data['name'],
        'username' => $data['username'],
        'email' => $data['email'],
        'role' => $data['role'],
        'password' => bcrypt($data['password']),
    ]);

    return redirect($this->redirectPath());
}
RabbitSC2's avatar

Perfect! :D

You're a star for putting up with me, thankyou so much for your help!

Please or to participate in this conversation.