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

PT-83's avatar
Level 7

Server 500 Upon Form Submission

Hi all, I am using laravel and forge to deploy my web app. On localhost, everything works fine. However, on the server when I complete a form registration, I get a server 500, and nothing is being passed to my database which I connected with tableplus GUI. I am using Laravel Authentication which I thought would work out of the box.

I will post code below but I am not sure if anything else code-wise is required.

Can you provide me with direction on how to get this functioning and perhaps a brief explanation?

Register controller

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;

class RegisterController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Register Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users as well as their
    | validation and creation. By default this controller uses a trait to
    | provide this functionality without requiring any additional code.
    |
    */

    use RegistersUsers;

    /**
     * Where to redirect users after registration.
     *
     * @var string
     */
    protected $redirectTo = RouteServiceProvider::HOME;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }

    /**
     * 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', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return \App\User
     */
    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
        ]);
    }
}

Web.php

<?php

use Illuminate\Support\Facades\Route;
use App\Mail\WelcomeMail;

Route::group(['middleware' => ['web']], function () {
    //
});

Route::group(['middleware' => 'web'], function () {
    Route::auth();

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

    Route::get('/home', 'HomeController@index');
});

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

Route::get('/email', function () {
    return new WelcomeMail();
});

Auth::routes();

Route::get('/contact/create', 'ContactController@create')->name('create');
Route::post('/contact', 'ContactController@store');

Route::get('/posts', 'PostController@index');
Route::get('/posts/create', 'PostController@create');
Route::post('/posts/create', 'PostController@store');
Route::get('/posts/{post}', 'PostController@show');
Route::get('/posts/{post}/edit', 'PostController@edit');
Route::patch('/posts/{post}', 'PostController@update');
Route::delete('/posts/{post}', 'PostController@destroy');

0 likes
3 replies
Tray2's avatar

What is the exact 500 error?

PT-83's avatar
Level 7

Hi @tray2 the error when I inspect in chrome is 'Failed to load resource: the server responded with a status of 500 () register:1

PT-83's avatar
PT-83
OP
Best Answer
Level 7

Ok, this is working now but it may not the best way.

Added Route::post('/register', 'Auth\RegisterController@create')->name('register'); to the web.php file,

Added protected function create(Request $request) { User::create($request->all()); return redirect('/home'); } to the RegistrationController.

That's it, it now passes data through to the database.

Please or to participate in this conversation.