I am trying to work on a Laravel PHP project and as i am new to this framework. First step i had to do is a Registration Form. However, when i click on the Submit button no error is given, and nothing is registrated in my users table.
Here is the code for my project so far :
My users migration table
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->boolean('sexe');
$table->integer('age');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
I added to the original two fields which are : "sexe a boolean F/M" and age
My RegisterController
<?php
namespace App\Http\Controllers;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Http\Request;
use Mail;
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 = '/register';
/**
* 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',
'sexe'=> 'required|in:male,female',
'age' => 'required|integer|max:100',
'email' => 'required', 'string', 'email', 'max:255', 'unique:users',
'password' => 'required', 'string', 'min:5', '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'],
'sexe' => $data['sexe'],
'age' => $data['age'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
/**
* Override default register method from RegistersUsers trait
*
* @param array $request
* @return redirect to $redirectTo
*/
public function register(Request $request)
{
$this->validator($request->all())->validate();
//add activation_key to the $request array
$activation_key = $this->getToken();
$request->request->add(['activation_key' => $activation_key]);
$user = $this->create($request->all());
//$this->guard()->login($user);
//write a code for send email to a user with activation link
$data = array('name' => $request['name'], 'email' => $request['email'], 'activation_link' => url('/activation/' . $activation_key));
Mail::send('emails.mail', $data, function($message) use ($data) {
$message->to($data['email'])
->subject('Activate Your Account');
$message->from('s.sajid@artisansweb.net');
});
return $this->registered($request, $user)
?: redirect($this->redirectPath())->with('success', 'We have sent an activation link on your email id. Please verify your account.');
print_r($request->input());
}
/**
* Generate a unique token
*
* @return unique token
*/
public function getToken() {
return hash_hmac('sha256', str_random(40), config('app.key'));
}
}
My Routes File
<?php
Route::auth();
Route::get('/home', 'HomeController@index');
Auth::routes();
Route::get('/register', 'RegisterController@create');
Route::post('/register', 'RegisterController@register');
Route::get('/', function () {
return view('welcome');
});
**My User.php Model**
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
//protected $table = 'users';
protected $fillable = [
'name','sexe','age','email','password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function setPasswordAttribute($password)
{
$this->attributes['password'] = bcrypt($password);
}
}
My blade file (register.blade.php)
<!DOCTYPE html>
<html>
<head>
<title>Interface d'Accueil</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<!------ Include the above in your HEAD tag ---------->
<style>
body{
background: -webkit-linear-gradient(left, #4c96d7, #4894d6);
}
.register{
margin-top: 3rem;
margin-right: 3rem;
padding: 3%;
}
.register-left{
text-align: center;
color: #fff;
margin-top: 4%;
}
.register-left input{
border: none;
border-radius: 1.5rem;
padding: 2%;
width: 60%;
background: #edad37;
font-weight: bold;
color: #383d41;
margin-top: 30%;
margin-bottom: 3%;
cursor: pointer;
}
.register-right{
padding-right: 50px;
margin-top: 7%;
background: #edad37;
border-top-left-radius: 10% 50%;
border-bottom-left-radius: 10% 50%;
border-top-right-radius: 10% 50%;
border-bottom-right-radius: 10% 50%;
}
.connexion{
background: #ec5749;
border-top-left-radius: 10% 50%;
border-bottom-left-radius: 10% 50%;
border-top-right-radius: 10% 50%;
border-bottom-right-radius: 10% 50%;
}
.register-left img{
margin-top: -1rem;
margin-left: -30rem;
}
.register-left p{
font-weight: lighter;
padding: 12%;
margin-top: -9%;
}
.register .register-form{
padding: 10%;
margin-top: 10%;
}
.btn-primary{
border: none;
border-radius: 1.5rem;
background: #0062cc;
color: #fff;
font-weight: 600;
width: 100%;
cursor: pointer;
}
.btnRegister{
float: right;
margin-top: 17%;
border: none;
border-radius: 1.5rem;
padding: 2%;
background: #0062cc;
color: #fff;
font-weight: 600;
width: 100%;
cursor: pointer;
}
.register .nav-tabs{
margin-top: 3%;
border: none;
background: #0062cc;
border-radius: 1.5rem;
width: 28%;
float: right;
}
.register .nav-tabs .nav-link{
padding: 2%;
height: 34px;
font-weight: 500;
color: #fff;
border-top-right-radius: 1.5rem;
border-bottom-right-radius: 2rem;
}
.register .nav-tabs .nav-link:hover{
border: none;
}
.nav .nav-tabs .nav-justified {
width: 100%;
text-align: center;
height:40px;
display: block;
float: right;
}
.register .nav-tabs .nav-link.active{
width: 100px;
color: #0062cc;
border: 2px solid #0062cc;
border-top-left-radius: 1.5rem;
border-bottom-left-radius: 1.5rem;
}
.register-heading{
text-align: center;
font-size: 1.5vw;
font-family: sans-serif;
margin-top: 8%;
margin-bottom: -15%;
color: #fff;
margin-left: -100px;
}
@keyframes mover {
0% { transform: translateY(0); }
100% { transform: translateY(-20px); }
}
</style>
</head>
<body>
<div class="container register">
<div class="row">
<div class="col-md-9 connexion">
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="login" role="tabpanel" aria-labelledby="login-tab">
<h3 class="register-heading">Déjà Membre? <u> Connectez Vous ici </u> </h3>
<div class="row register-form">
<div class="col-md-12 profile_card">
<form class="form-inline">
<div class="col-md-4">
<div class="form-group">
<input type="text" class="form-control" placeholder="Entrez votre Email" value="" />
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<input type="password" class="form-control" placeholder="Mot de Passe *" value="" />
</div>
</div>
<div class="col-md-4">
<div class="float-right">
<input type="submit" class="btn btn-primary" value="Se Connecter" />
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="container register">
<div class="row">
<div class="col-md-3 register-left">
<img class="logo" align="left" src="http://localhost:8012/Real-Time-Chat-master/app/public/images/ijjilogo.png"/>
<br/>
</div>
<div class="col-md-9 register-right">
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
<h3 class="register-heading">Créer un Nouveau compte <u>Gratuitement</u></h3>
<form method="POST" role="form" action="//IJJI/resources/views/chat.blade.php">
<meta name="csrf-token" content="">
<div class="row register-form">
<div class="col-md-6">
<div class="form-group">
<input id="name" name="name"type="text" class="form-control" placeholder="Entrez ici votre Pseudo *" value="" />
</div>
<div class="form-group">
<div class="maxl">
<label class="radio inline">
<input id="homme" type="radio" name="sexe" value="homme" checked>
<span> Homme </span>
</label>
<label class="radio inline">
<input id="femme" type="radio" name="sexe" value="femme">
<span>Femme </span>
</label>
</div>
</div>
<div class="form-group">
<input id="age" name="age" type="integer" class="form-control" placeholder="Saisissez vore age *" value="" />
</div>
<div class="form-group">
<input id="Email" name="email" type="email" class="form-control" placeholder="Saisissez votre Email *" value="" />
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input id="password" name="password" type="password" class="form-control" placeholder="Entrez votre Mot de Passe *" value="" />
</div>
<div class="form-group">
<input id="confirmpassword" name="confirmpassword" type="password" class="form-control" placeholder="Confrimez votre Mot de Passe *" value="" />
</div>
<button type="submit" class="btnRegister">
Je deviens membre Gratuitement
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
I have done php artisan make auth generated the files, made .env file adequate to my mysql DB with the username and password, even checked the phpmyadmin configuration, but all in vain.
Please help, because after 4 days of search in google websites i can't figure out where i am wrong.
P.S : Another thing that could be wrong is that code like this :
@section
@endsection
never get accepted and just shows like normal text on my browser.
Thanks a lot for your help
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire