I'm trying to create a user with my custom authentication and getting 500 error while posting data. I gues I messed something wrong with user model. Because If I trying to return the input from the form it's return succefull but If I'm trying to post data to DB I'm getting 500 error. ps .env is configured correctly. User model:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
protected $fillable = [
'name', 'password',
];
}
Auth Controller:
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\User;
class AuthController extends Controller
{
//Login function
function register(){
return view('auth.register');
}
//Create user in DB
function create(Request $request){
//Validate requests
$request->validate([
'name'=>'required',
'password'=>'required'
]);
//Insert data into database
$user = new User;
$user->name = $request->name;
$user->password = Hash::make($request->password);
$save = $user->save();
}
}
Routes:
**<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AuthController;
//Register Route
Route::get('/auth/register', [AuthController::class, 'register']);
Route::post('/auth/create', [AuthController::class, 'create'])->name('auth.create');**
APP_DEBUG=true
in your.env
file or look in the logs (storage/logs/laravel.log
)use Hash;
. This could be case for getting error.