I am creating a simple login function on my website with a registration feature. The registration feature is functional and users are appearing in the database. However, when I try to register new user, it did not inserted into database and stay on the same page and refresh data in form register. When I enter credentials, be it correct or wrong, the page would just reload with no error messages.
I've had this problem for a few days now and it really irritates me that I can't solve it. I'm at my wit's end so please help me!
This is my 'register.blade.php'
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-header text-center h2"></div>
<div class="card-body">
<form method="POST" action="">
@csrf
<div class="form-group row">
<label for="text" class="col-md-4 col-form-label text-md-right"></label>
<div class="col-md-6">
<input id="fname" type="text" class="form-control" name="first_name" required autocomplete="first-name">
</div>
</div>
<div class="form-group row">
<label for="text" class="col-md-4 col-form-label text-md-right"></label>
<div class="col-md-6">
<input id="fname" type="text" class="form-control" name="last_name" required autocomplete="last-name">
</div>
</div>
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right"></label>
<div class="col-md-6">
<input id="email" type="email" class="form-control @error('email') is-invalid @enderror" name="email" value="" required autocomplete="email">
@error('email')
<span class="invalid-feedback" role="alert">
<strong></strong>
</span>
@enderror
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right"></label>
<div class="col-md-6">
<input id="password" type="password" class="form-control @error('password') is-invalid @enderror" name="password" required autocomplete="new-password">
@error('password')
<span class="invalid-feedback" role="alert">
<strong></strong>
</span>
@enderror
</div>
</div>
<div class="form-group row">
<label for="password-confirm" class="col-md-4 col-form-label text-md-right"></label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required autocomplete="new-password">
</div>
</div>
<div class="form-group row">
<label for="text" class="col-md-4 col-form-label text-md-right"></label>
<div class="col-md-6">
<input id="position" type="text" class="form-control" name="postion" required autocomplete="position">
</div>
</div>
<div class="form-group row">
<label for="address" class="col-md-4 col-form-label text-md-right"></label>
<div class="col-md-6">
<input id="address" type="address" class="form-control @error('address') is-invalid @enderror" name="address" value="" required autocomplete="address">
@error('address')
<span class="invalid-feedback" role="alert">
<strong></strong>
</span>
@enderror
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
@endsection
This is my route web.php
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
Route::get('/', function () {
return view('auth.login');
});
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Route::group(['as'=>'admin.','prefix'=>'admin','namespace'=>'Admin','middleware'=>
['auth','admin']], function (){
Route::get('dashboard','DashboardController@index')->name('dashboard');
});
Route::group(['as'=>'author.','prefix'=>'author','namespace'=>'Author','middleware'=>
['auth','author']], function (){
Route::get('dashboard','DashboardController@index')->name('dashboard');
Route::post('register', 'RegisterController@register');
});
This is my RegisterController
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Support\Facades\Auth;
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;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
if(Auth::check() && Auth::user()->role->id == 1){
$this -> redirectTo = route('admin.dashboard');
}else {
$this -> redirectTo = route('author.dashboard');
}
$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, [
'first_name' => ['required', 'string', 'max:255'],
'last_name' => ['required', 'string', 'max:255'],
'address' => ['required', 'string', 'max:255'],
'position' => ['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([
'role_id' => 2,
'first_name' => $data['name'],
'last_name' => $data['last_name'],
'address' => $data['address'],
'email' => $data['email'],
'positin' => $data['position'],
'password' => Hash::make($data['password']),
]);
}
}
This my route list
+--------+----------+------------------------+------------------+------------------------------------------------------------------------+-----------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+------------------------+------------------+------------------------------------------------------------------------+-----------------+
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | admin/dashboard | admin.dashboard | App\Http\Controllers\Admin\DashboardController@index | web,auth,admin |
| | GET|HEAD | api/user | | Closure | api,auth:api |
| | GET|HEAD | author/dashboard | author.dashboard | App\Http\Controllers\Author\DashboardController@index | web,auth,author |
| | GET|HEAD | home | home | App\Http\Controllers\HomeController@index | web,auth |
| | GET|HEAD | login | login | App\Http\Controllers\Auth\LoginController@showLoginForm | web,guest |
| | POST | login | | App\Http\Controllers\Auth\LoginController@login | web,guest |
| | POST | logout | logout | App\Http\Controllers\Auth\LoginController@logout | web |
| | GET|HEAD | password/confirm | password.confirm | App\Http\Controllers\Auth\ConfirmPasswordController@showConfirmForm | web,auth |
| | POST | password/confirm | | App\Http\Controllers\Auth\ConfirmPasswordController@confirm | web,auth |
| | POST | password/email | password.email | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail | web,guest |
| | GET|HEAD | password/reset | password.request | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm | web,guest |
| | POST | password/reset | password.update | App\Http\Controllers\Auth\ResetPasswordController@reset | web,guest |
| | GET|HEAD | password/reset/{token} | password.reset | App\Http\Controllers\Auth\ResetPasswordController@showResetForm | web,guest |
| | GET|HEAD | register | register | App\Http\Controllers\Auth\RegisterController@showRegistrationForm | web,guest |
| | POST | register | | App\Http\Controllers\Auth\RegisterController@register | web,guest |
+--------+----------+------------------------+------------------+------------------------------------------------------------------------+-----------------+
virakran@Lenovo-ideapad:~/Desktop/StudentFollowupG6$
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire