error password change in edit profile laravel 7 undefined variable - php

i created 2 pages. First it's edit profile and second for change password, this pages and functionnality worked. when the password change and the other inputs are on separate pages all work and all this changes. but when i try to put the password change on the profile edit i get this error:
Facade\Ignition\Exceptions\ViewException
Undefined variable: user (View: /home/mokoch/Bureau/projetabonnementpayant/resources/views/profile/edit.blade.php)
http://127.0.0.1:8000/profile
MatchOldPassword.php
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
use Illuminate\Support\Facades\Hash;
class MatchOldPassword implements Rule
{
/**
* Determine if the validation rule passes.
*
* #param string $attribute
* #param mixed $value
* #return bool
*/
public function passes($attribute, $value)
{
return Hash::check($value, auth()->user()->password);
}
/**
* Get the validation error message.
*
* #return string
*/
public function message()
{
return 'The :attribute is match with old password.';
}
}
edit.blade.php
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">
Update Profile
</div>
<div class="card-body">
<form method="POST" action="{{ route('profile.edit') }}">
#method('patch')
#csrf
<div class="form-group row">
<label for="name" class="col-md-4 col-form-label text-md-right">{{ __('Name') }}</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control #error('name') is-invalid #enderror" name="name" value="{{ old('name', $user->name) }}" autocomplete="name" autofocus>
#error('name')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="firstname" class="col-md-4 col-form-label text-md-right">{{ __('firstname') }}</label>
<div class="col-md-6">
<input id="firstname" type="text" class="form-control #error('firstname') is-invalid #enderror" name="firstname" value="{{ old('firstname', $user->firstname) }}" autocomplete="firstname" autofocus>
#error('firstname')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="address" class="col-md-4 col-form-label text-md-right">{{ __('address') }}</label>
<div class="col-md-6">
<input id="address" type="text" class="form-control #error('address') is-invalid #enderror" address="address" value="{{ old('address', $user->address) }}" autocomplete="address" autofocus>
#error('address')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="city" class="col-md-4 col-form-label text-md-right">{{ __('city') }}</label>
<div class="col-md-6">
<input id="city" type="text" class="form-control #error('city') is-invalid #enderror" city="city" value="{{ old('city', $user->city) }}" autocomplete="city" autofocus>
#error('city')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="phone" class="col-md-4 col-form-label text-md-right">{{ __('phone') }}</label>
<div class="col-md-6">
<input id="phone" type="text" class="form-control #error('phone') is-invalid #enderror" phone="phone" value="{{ old('phone', $user->phone) }}" autocomplete="phone" autofocus>
#error('phone')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="profile_image" class="col-md-4 col-form-label text-md-right">{{ __('profile_image') }}</label>
<div class="col-md-6">
<input id="profile_image" type="text" class="form-control #error('profile_image') is-invalid #enderror" profile_image="profile_image" value="{{ old('profile_image', $user->profile_image) }}" autocomplete="profile_image" autofocus>
#error('profile_image')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="zipcode" class="col-md-4 col-form-label text-md-right">{{ __('zipcode') }}</label>
<div class="col-md-6">
<input id="zipcode" type="text" class="form-control #error('zipcode') is-invalid #enderror" zipcode="zipcode" value="{{ old('zipcode', $user->zipcode) }}" autocomplete="zipcode" autofocus>
#error('zipcode')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="pseudo" class="col-md-4 col-form-label text-md-right">{{ __('pseudo') }}</label>
<div class="col-md-6">
<input id="pseudo" type="text" class="form-control #error('pseudo') is-invalid #enderror" pseudo="pseudo" value="{{ old('pseudo', $user->pseudo) }}" autocomplete="pseudo" autofocus>
#error('pseudo')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="birthday" class="col-md-4 col-form-label text-md-right">{{ __('birthday') }}</label>
<div class="col-md-6">
<input id="birthday" type="date" class="form-control #error('birthday') is-invalid #enderror" birthday="birthday" value="{{ old('birthday', $user->birthday) }}" autocomplete="birthday" autofocus>
#error('birthday')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control #error('email') is-invalid #enderror" name="email" value="{{ old('email', $user->email) }}" autocomplete="email">
#error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">Current Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="current_password" autocomplete="current-password">
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">New Password</label>
<div class="col-md-6">
<input id="new_password" type="password" class="form-control" name="new_password" autocomplete="current-password">
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">New Confirm Password</label>
<div class="col-md-6">
<input id="new_confirm_password" type="password" class="form-control" name="new_confirm_password" autocomplete="current-password">
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
Update Profile
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
changePassword.blade.php
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Laravel - Change Password with Current</div>
<div class="card-body">
<form method="POST" action="{{ route('profile') }}">
#csrf
#foreach ($errors->all() as $error)
<p class="text-danger">{{ $error }}</p>
#endforeach
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">Current Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="current_password" autocomplete="current-password">
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">New Password</label>
<div class="col-md-6">
<input id="new_password" type="password" class="form-control" name="new_password" autocomplete="current-password">
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">New Confirm Password</label>
<div class="col-md-6">
<input id="new_confirm_password" type="password" class="form-control" name="new_confirm_password" autocomplete="current-password">
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-8 offset-md-4">
<button type="submit" class="btn btn-primary">
Update Password
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
ChangePasswordController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Rules\MatchOldPassword;
use Illuminate\Support\Facades\Hash;
use App\User;
class ChangePasswordController extends Controller
{
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* #return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
return view('profile.edit');
}
/**
* Show the application dashboard.
*
* #return \Illuminate\Contracts\Support\Renderable
*/
public function store(Request $request)
{
$request->validate([
'current_password' => ['required', new MatchOldPassword],
'new_password' => ['required'],
'new_confirm_password' => ['same:new_password'],
]);
User::find(auth()->user()->id)->update(['password'=> Hash::make($request->new_password)]);
dd('Password change successfully.');
}
}
Web.php
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
Route::group(['middleware' => 'auth'], function () {
Route::any('profile', 'ProfileController#edit')->name('profile.edit');
});
Route::group(['middleware' => 'auth'], function () {
Route::get('profile', 'ProfileController#edit')
->name('profile.edit');
Route::patch('profile', 'ProfileController#update')
->name('profile.update');
Route::get('profile', 'ChangePasswordController#index');
Route::post('profile', 'ChangePasswordController#store');
});
PasswordController.php
<?php
namespace App\Http\Controllers;
class PasswordController extends Controller
{
/**
* #return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function edit()
{
return view('profile.edit');
}
}
UpdateProfileRequest.php controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class UpdateProfileRequest extends Controller
{
/**
* Update user's profile
*
* #param UpdateProfileRequest $request
* #return \Illuminate\Contracts\Support\Renderable
*/
public function update(UpdateProfileRequest $request)
{
$request->user()->update(
$request->all()
);
return redirect()->route('profile.edit');
}
}
UpdateProfileRequest.php
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\Rule;
class UpdateProfileRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* #return bool
*/
public function authorize()
{
return Auth::check();
}
/**
* Get the validation rules that apply to the request.
*
* #return array
*/
public function rules()
{
return [
'name' => [
'required', 'string', 'max:255'
],
'username' => [
'required', 'string', 'max:255',
Rule::unique('users', 'username')->ignore(Auth::user()->id)
],
'email' => [
'required', 'email', 'max:255',
Rule::unique('users', 'email')->ignore(Auth::user()->id)
],
];
}
}
Someone can help me leave this error?

Error is pretty straight forward, You are using an undefined variable.
You can either add the variable:
public function edit()
{
return view('profile.edit', ['user' => auth()->user()]);
}
Or inside your blade use auth()->user() directly instead of $user

Related

Customise login in Laravel 8 [duplicate]

This question already has answers here:
Laravel login with username instead of email
(2 answers)
Closed 1 year ago.
I tried to change the login method by replacing the email with the username.
register.blade.php
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Register') }}</div>
<div class="card-body">
<form method="POST" action="{{ route('register') }}">
#csrf
<div class="form-group row">
<label for="name" class="col-md-4 col-form-label text-md-right">{{ __('Username') }}</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control #error('name') is-invalid #enderror" name="name" value="{{ old('name') }}" required autocomplete="name" autofocus>
#error('name')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="telegram" class="col-md-4 col-form-label text-md-right">{{ __('Telegram') }}</label>
<div class="col-md-6">
<input id="telegram" type="telegram" class="form-control #error('telegram') is-invalid #enderror" name="telegram" value="{{ old('telegram') }}" required autocomplete="telegram">
#error('telegram')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="skills" class="col-md-4 col-form-label text-md-right">{{ __('Skills') }}</label>
<div class="col-md-6">
<input id="skills" type="skills" class="form-control #error('skills') is-invalid #enderror" name="skills" value="{{ old('skills') }}" required autocomplete="skills">
#error('skills')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="education" class="col-md-4 col-form-label text-md-right">{{ __('Few world about you') }}</label>
<div class="col-md-6">
<input id="education" type="education" class="form-control #error('education') is-invalid #enderror" name="education" value="{{ old('education') }}" required autocomplete="education">
#error('education')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="sponsor" class="col-md-4 col-form-label text-md-right">{{ __('Come from :') }}</label>
<div class="col-md-6">
<input id="sponsor" type="sponsor" class="form-control #error('sponsor') is-invalid #enderror" name="sponsor" value="{{ old('sponsor') }}" required autocomplete="sponsor">
#error('sponsor')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</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>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</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 mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Register') }}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
login.blade.php
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Login') }}</div>
<div class="card-body">
<form method="POST" action="{{ route('login') }}">
#csrf
<div class="form-group row">
<label for="name" class="col-md-4 col-form-label text-md-right">{{ __('Username') }}</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control #error('name') is-invalid #enderror" name="name" value="{{ old('name') }}" required autocomplete="name" autofocus>
#error('name')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control #error('password') is-invalid #enderror" name="password" required autocomplete="current-password">
#error('password')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<div class="col-md-6 offset-md-4">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="remember" id="remember" {{ old('remember') ? 'checked' : '' }}>
<label class="form-check-label" for="remember">
{{ __('Remember Me') }}
</label>
</div>
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-8 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Login') }}
</button>
#if (Route::has('password.request'))
<a class="btn btn-link" href="{{ route('password.request') }}">
{{ __('Forgot Your Password?') }}
</a>
#endif
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
database personnal access token
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePersonalAccessTokensTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('personal_access_tokens', function (Blueprint $table) {
$table->id();
$table->morphs('tokenable');
$table->string('name');
$table->string('token', 64)->unique();
$table->text('abilities')->nullable();
$table->timestamp('last_used_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::dropIfExists('personal_access_tokens');
}
}
database user
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name')->nullable()->unique();
$table->string('education')->nullable();
$table->string('sponsor')->nullable();
$table->string('telegram')->unique();
$table->boolean('is_admin')->default(0);
$table->text('skills')->nullable();
$table->boolean('is_deleted')->default(0);
$table->boolean('is_verified')->default(0);
$table->boolean('is_banned')->default(0);
$table->integer('rank')->default(0);
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
logincontroller
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* #var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
Model user
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
use \HighIdeas\UsersOnline\Traits\UsersOnlineTrait;
/**
* The attributes that are mass assignable.
*
* #var string[]
*/
protected $fillable = [
'name',
'password',
'skills',
'education',
'sponsor',
'telegram',
];
/**
* The attributes that should be hidden for serialization.
*
* #var array
*/
protected $hidden = [
'password',
'remember_token',
];
// /**
// * The attributes that should be cast.
// *
// * #var array
// */
// protected $casts = [
// 'email_verified_at' => 'datetime',
// ];
public function topics()
{
return $this->hasMany('App\Models\Discussion');
}
public function replies()
{
return $this->hasMany('App\Models\DiscussionReply');
}
}
But I don't know why it doesn't login me, registering all is working fine. But it's just the login that doesn't connect, its loading but nothing changes. I have almost finished my forum project, I just have this point to do and another. Anyone have any idea where the problem is?
By default, Laravel uses email as the key for the login form.
Check here: https://github.com/laravel/ui/blob/b3e804559bf3973ecca160a4ae1068e6c7c167c6/auth-backend/AuthenticatesUsers.php#L150
Override this function in your controller as:
/**
* Get the login username to be used by the controller.
*
* #return string
*/
public function username()
{
return 'name';
}
It will start working.

user profile manager with laravel7

With laravel7, I want to allow each user to be able to modify their profile, but I can't. With my code when the connected user wants to modify his profile there is a message telling him that he is not authorized. Which is not normal. I do not know where my error lies. Please help me!
Routes:
route::get('/profiles/{user}', 'ProfileController#show')->name('profiles.show');
route::get('/profiles/{user}/edit', 'ProfileController#edit')->name('profiles.edit');
route::patch('/profiles/{user}', 'ProfileController#update')->name('profiles.update');
My update view:
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header alert-primary">{{ __('Update my profile') }}</div>
<div class="card-body">
<form method="POST" action="{{ route('profiles.update', ['user' => $user]) }}" >
#csrf
#method('PATCH')
<div class="form-group row">
<label for="firstname" class="col-md-4 col-form-label text-md-right">{{ __('Firstname') }}</label>
<div class="col-md-6">
<input id="firstname" type="text" class="form-control #error('firstname') is-invalid #enderror" name="firstname" value="{{ old('firstname') ?? $user->firstname}}" required autocomplete="firstname" autofocus>
#error('firstname')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="lastname" class="col-md-4 col-form-label text-md-right">{{ __('Lastname') }}</label>
<div class="col-md-6">
<input id="lastname" type="text" class="form-control #error('lastname') is-invalid #enderror" name="lastname" value="{{ old('lastname') ?? $user->lastname}}" required autocomplete="lastname" autofocus>
#error('lastname')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="role" class="col-md-4 col-form-label text-md-right">{{ __('Role') }}</label>
<div class="col-md-6">
<input id="role" type="text" class="form-control #error('role') is-invalid #enderror" name="role" value="{{ old('role') ?? $user->role}}" required autocomplete="role" autofocus>
#error('role')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="phone" class="col-md-4 col-form-label text-md-right">{{ __('Phone') }}</label>
<div class="col-md-6">
<input id="phone" type="text" class="form-control #error('phone') is-invalid #enderror" name="phone" value="{{ old('phone') ?? $user->phone}}" required autocomplete="phone" autofocus>
#error('phone')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control #error('email') is-invalid #enderror" name="email" value="{{ old('email') ?? $user->email}}" required autocomplete="email">
#error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="adress" class="col-md-4 col-form-label text-md-right">{{ __('Adress') }}</label>
<div class="col-md-6">
<input id="adress" type="text" class="form-control #error('adress') is-invalid #enderror" name="adress" value="{{ old('adress') ?? $user->adress}}" required autocomplete="adress" autofocus>
#error('adress')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="profession" class="col-md-4 col-form-label text-md-right">{{ __('Profession') }}</label>
<div class="col-md-6">
<input id="profession" type="text" class="form-control #error('profession') is-invalid #enderror" name="profession" value="{{ old('profession') ?? $user->profession}}" required autocomplete="profession" autofocus>
#error('profession')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</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>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</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 mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Update') }}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
My controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use app\User;
use Validator;
use Illuminate\Foundation\Validation\ValidatesRequests;
class ProfileController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show(User $user)
{
//
return view ('profiles.show', compact ('user'));
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit(User $user)
{
//
$this->authorize('update', $user->profile);
return view ('profiles.edit', compact ('user'));
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update( User $user)
{
//
$this->authorize ('update', $user->profile);
$data = request()->validate ([
'firstname'=>'required',
'Lastname'=>'required',
'phone' => 'required' ,
'email' => 'required',
'adress' => 'required',
'profession' => 'required',
'password' => 'required',
]);
auth()->$user->update($data);
return redirect()->route('profiles.show', ['user'=> $user]);
}
}
My model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Profile extends Model
{
protected $guarded = [];
public function user(){
return $this->belongsTo('App\User');
}
}
thanks
Grab your Routes in Auth Middleware.
Route::group(['middleware' => ['auth']], function () {
route::get('/profiles/{user}', 'ProfileController#show')->name('profiles.show');
route::get('/profiles/{user}/edit', 'ProfileController#edit')->name('profiles.edit');
route::patch('/profiles/{user}', 'ProfileController#update')->name('profiles.update');
});

Laravel - login messages

I'm currently working on Laravel 5.8 version and I'm using Laravel make:auth option. That created me login and registration and all I did i add a phone number. So this is how it is looking in my register.blade.php :
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Register') }}</div>
<div class="card-body">
<form method="POST" action="{{ route('register') }}">
#csrf
<div class="form-group row">
<label for="name" class="col-md-4 col-form-label text-md-right">{{ __('Name') }}</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control #error('name') is-invalid #enderror" name="name" value="{{ old('name') }}" required autocomplete="name" autofocus>
#error('name')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control #error('email') is-invalid #enderror" name="email" value="{{ old('email') }}">
#error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</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>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</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="phone" class="col-md-4 col-form-label text-md-right">{{ __('Phone Number') }}</label>
<div class="col-md-6">
<input id="phone" type="phone" class="form-control" name="phone" required>
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Register') }}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
So this section:
#error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
shows me span message if email has already been taken. So how can I do that #error('phone') for my phone? I coded in my RegisterController.php that my phone my be unique:users?
Please help me with this #error message!
This will check User Phone Number Like Email. It Will Allocate Unique user Phone Number
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:6|confirmed',
'phone' => 'required|unique:users,phone'
]);
}
For Displaying Errors In Register Blade
#error('phone')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
You need to add something like this to RegisterController.php
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:6|confirmed',
'phone' => 'required'
]);
}

Trying to hash password in laravel by inputting new user in existing database

So im new to laravel and I want to, as the admin, add new users to the system but I want these new users to be added to the same database as the default one that created by php artisan ui vue --auth command. I edited the register.blade.php file made by the auth and added more fields. I am running into an error of The acctyp field is required as well ass The gender field is required whenever I want to add a new user whether through the register or my other blade.
This is the code:
register.blade.php :
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Register') }}</div>
<div class="card-body">
<form method="POST" action="{{ route('register') }}">
#csrf
<div class="form-group row">
<label for="acctyp" class="col-md-4 col-form-label text-md-right">{{ __('Account Type') }}</label>
<div class="col-md-6">
<select name="acctyp" id="acctype" class="form-control #error('acctyp') is-invalid #enderror" name="acctyp" value="{{ old('acctyp') }}" required autocomplete="acctyp" autofocus>
<option value="">Choose Account...</option>
<option value="">Admin</option>
<option value="">Records</option>
<option value="">H.O.D</option>
<option value="">Teacher</option>
<option value="">Student</option>
</select>
#error('acctyp')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="name" class="col-md-4 col-form-label text-md-right">{{ __('Name') }}</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control #error('name') is-invalid #enderror" name="name" value="{{ old('name') }}" required autocomplete="name" autofocus>
#error('name')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="surname" class="col-md-4 col-form-label text-md-right">{{ __('Surname') }}</label>
<div class="col-md-6">
<input id="surname" type="text" class="form-control #error('name') is-invalid #enderror" name="surname" value="{{ old('surname') }}" required autocomplete="surname" autofocus>
#error('surname')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="dob" class="col-md-4 col-form-label text-md-right">{{ __('D.O.B') }}</label>
<div class="col-md-6">
<input id="dob" type="date" class="form-control #error('dob') is-invalid #enderror" name="dob" value="{{ old('dob') }}" required autocomplete="dob" autofocus>
#error('dob')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="gender" class="col-md-4 col-form-label text-md-right">{{ __('Gender') }}</label>
<div class="col-md-6">
<select name="gender" id="gender" class="form-control #error('gender') is-invalid #enderror" name="gender" value="{{ old('gender') }}" required autocomplete="gender" autofocus>
<option value="">Choose Gender...</option>
<option value="">Female</option>
<option value="">Male</option>
<option value="">Other</option>
</select>
#error('acctyp')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control #error('email') is-invalid #enderror" name="email" value="{{ old('email') }}" required autocomplete="email">
#error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="userid" class="col-md-4 col-form-label text-md-right">{{ __('User ID') }}</label>
<div class="col-md-6">
<input id="userid" type="text" class="form-control #error('userid') is-invalid #enderror" name="userid" value="{{ old('userid') }}" required autocomplete="userid" autofocus>
#error('userid')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</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>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</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 mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Register') }}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
create.blade.php ->(this is in accounts folder)
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Add New User') }}</div>
<div class="card-body">
<form method="POST" action="{{ route('register') }}">
#csrf
<div class="form-group row">
<label for="acctyp" class="col-md-4 col-form-label text-md-right">{{ __('Account Type') }}</label>
<div class="col-md-6">
<select name="acctyp" id="acctype" class="form-control #error('acctyp') is-invalid #enderror" name="acctyp" value="{{ old('acctyp') }}" required autocomplete="acctyp" autofocus>
<option value="">Choose Account...</option>
<option value="">Admin</option>
<option value="">Records</option>
<option value="">H.O.D</option>
<option value="">Teacher</option>
<option value="">Student</option>
</select>
#error('acctyp')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="name" class="col-md-4 col-form-label text-md-right">{{ __('Name') }}</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control #error('name') is-invalid #enderror" name="name" value="{{ old('name') }}" required autocomplete="name" autofocus>
#error('name')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="surname" class="col-md-4 col-form-label text-md-right">{{ __('Surname') }}</label>
<div class="col-md-6">
<input id="surname" type="text" class="form-control #error('name') is-invalid #enderror" name="surname" value="{{ old('surname') }}" required autocomplete="surname" autofocus>
#error('surname')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="dob" class="col-md-4 col-form-label text-md-right">{{ __('D.O.B') }}</label>
<div class="col-md-6">
<input id="dob" type="date" class="form-control #error('dob') is-invalid #enderror" name="dob" value="{{ old('dob') }}" required autocomplete="dob" autofocus>
#error('dob')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="gender" class="col-md-4 col-form-label text-md-right">{{ __('Gender') }}</label>
<div class="col-md-6">
<select name="gender" id="gender" class="form-control #error('gender') is-invalid #enderror" name="gender" value="{{ old('gender') }}" required autocomplete="gender" autofocus>
<option value="">Choose Gender...</option>
<option value="">Female</option>
<option value="">Male</option>
<option value="">Other</option>
</select>
#error('acctyp')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control #error('email') is-invalid #enderror" name="email" value="{{ old('email') }}" required autocomplete="email">
#error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="userid" class="col-md-4 col-form-label text-md-right">{{ __('User ID') }}</label>
<div class="col-md-6">
<input id="userid" type="text" class="form-control #error('userid') is-invalid #enderror" name="userid" value="{{ old('userid') }}" required autocomplete="userid" autofocus>
#error('userid')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</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>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</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 mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Register') }}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
create_users_table :
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('acctyp');
$table->string('name');
$table->string('surname');
$table->string('dob');
$table->string('gender');
$table->string('userid');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
create_accounts_table :
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateAccountsTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('accounts', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('acctyp');
$table->string('name');
$table->string('surname');
$table->string('dob');
$table->string('gender');
$table->string('userid');
$table->string('email')->unique();
$table->string('password');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::dropIfExists('accounts');
}
}
user model :
<?php
namespace App;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'acctyp', 'name', 'surname', 'dob', 'gender', 'email', 'userid', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* #var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* #var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
account model :
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Account extends Model
{
//primary key
protected $primaryKey = 'userid';
// Indicating that the primary key is not a number.
public $incrementing = false;
}
register controller :
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
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 = '/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, [
'acctyp' => ['required', 'string', 'max:255'],
'name' => ['required', 'string', 'max:255'],
'surname' => ['required', 'string', 'max:255'],
'dob' => ['required', 'string', 'max:255'],
'gender' => ['required', 'string', 'max:255'],
'userid' => ['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([
'acctyp' => $data['acctyp'],
'name' => $data['name'],
'surname' => $data['surname'],
'dob' => $data['dob'],
'gender' => $data['gender'],
'userid' => $data['userid'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
}
accounts controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Account;
use App\User;
class AccountsController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$accounts = Account::all();
return view('accounts.index')->with('accounts', $accounts);
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
return view('accounts.create');
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
'acctyp' => 'required',
'name' => 'required',
'surname' => 'required',
'dob' => 'required',
'gender' => 'required',
'email' => 'required',
'userid' => 'required',
'password' => 'required',
]);
$account = new User;
$account->acctyp = $request->input('acctyp');
$account->name = $request->input('name');
$account->surname = $request->input('surname');
$account->dob = $request->input('dob');
$account->gender = $request->input('gender');
$account->email = $request->input('email');
$account->userid = $request->input('userid');
$account->password = $request->input('password');
return redirect('/accounts')->with('success', 'New User Added!');
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
How can I achieve adding a new user and how can i fix the errors I'm getting?
You need to set values for the <option> elements in your <select>s. Depending on what values you want/need either set them specifically:
<select name="acctyp" id="acctype" class="form-control #error('acctyp') is-invalid #enderror" name="acctyp" value="{{ old('acctyp') }}" required autocomplete="acctyp" autofocus>
<option value="">Choose Account...</option>
<option value="admin">Admin</option>
<option value="records">Records</option>
<option value="hod">H.O.D</option>
<option value="teacher">Teacher</option>
<option value="student">Student</option>
</select>
or remove the value="" part to use the <option>'s text as value:
<select name="acctyp" id="acctype" class="form-control #error('acctyp') is-invalid #enderror" name="acctyp" value="{{ old('acctyp') }}" required autocomplete="acctyp" autofocus>
<option value="">Choose Account...</option>
<option>Admin</option>
<option>Records</option>
<option>H.O.D</option>
<option>Teacher</option>
<option>Student</option>
</select>
This will use Admin,Records,H.O.D.,Teacher,Student as values
Same goes for your gender select.

How to make the login and register work with the code below

I am working on a laravel webshop and I have some problems with the Authentication, login and register. First of all, if I try to login with my email and password, who are already registered in the database, it will say "These credentials do not match our records." So it doesn't recognize my data. If I will navigate to the page it will actually recognize my email.
If I try to register it doesn't do anything.
I already have tried to do php artisan make:auth again but that won't change anything. Also, I have checked my models as following: I did some dd(); in the validator and in the create(){} but the dd(); will not launch in the create function so I suppose the create function isn't triggered.
//Login controller:
class LoginController extends Controller
{
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* #var string
*/
protected $redirectTo = '/';
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
//Register controller:
protected function validator(array $data)
{
return Validator::make($data, [
'gebruikersnaam' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255',
'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
'voornaam' => ['required', 'string', 'max:255'],
'achternaam' => ['required', 'string', 'max:255'],
'telefoonnummer' => ['required', 'string','min:9' ,'max:255'],
'klant_afbeelding' => ['required', 'string', 'max:255'],
]);
}
1. /**
* Create a new user instance after a valid registration.
*
* #param array $data
* #return \App\User
*/
protected function create(array $data)
{
return User::create([
'gebruikersnaam' => $data['gebruikersnaam'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'voornaam' => $data['voornaam'],
'achternaam' => $data['achternaam'],
'telefoonnummer' => $data['telefoonnummer'],
'klant_afbeelding' => $data['klant_afbeelding'],
]);
}
//User class:
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'gebruikersnaam', 'email', 'password','voornaam','achternaam',
'telefoonnummer','klant_afbeelding'
];
/**
* The attributes that should be hidden for arrays.
*
* #var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* #var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
//My routes:
<?php
Route::get('/', function () {
return view('home');
});
// Route::get('/', function (Request $request) {
// $data = $request->validate([
// 'message' => 'required|max:255',
// 'rating' => 'required|url|max:255',
// ]);
//
// return view('home');
// });
Route::get('/Profiel', 'ProfielController#Profiel');
Route::get('/home', 'HomeController#index')->name('home');
Route::get('/home', 'HomeController#Home' );
// route voor de review submit
Route::resource('reviewSubmit', 'ReviewController');
Route::get('/Profiel', 'ProfielController#Profiel');
Route::post('/profielupdate', 'ProfielController#update');
Route::post('/niewsbriefsubscribe', 'HomeController#subscribe');
Auth::routes();
Route::get('login', 'Auth\LoginController#showLoginForm')->name('login');
Route::get('register', 'Auth\RegisterController#showRegistrationForm')->name('register');
Route::post('register', 'Auth\RegisterController#register');
Route::get('/home', 'HomeController#index')->name('home');
//Login view
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Login') }}</div>
<div class="card-body">
<form method="POST" action="{{ route('login') }}">
#csrf
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control #error('email') is-invalid #enderror" name="email" value="{{ old('email') }}" required autocomplete="email" autofocus>
#error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control #error('password') is-invalid #enderror" name="password" required autocomplete="current-password">
#error('password')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<div class="col-md-6 offset-md-4">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="remember" id="remember" {{ old('remember') ? 'checked' : '' }}>
<label class="form-check-label" for="remember">
{{ __('Remember Me') }}
</label>
</div>
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-8 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Login') }}
</button>
#if (Route::has('password.request'))
<a class="btn btn-link" href="{{ route('password.request') }}">
{{ __('Forgot Your Password?') }}
</a>
#endif
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
//Register view
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Register') }}</div>
<div class="card-body">
<form method="POST" action="{{ route('register') }}">
#csrf
<div class="form-group row">
<label for="gebruikersnaam" class="col-md-4 col-form-label text-md-right">{{ __('Gebruikersnaam') }}</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control #error('name') is-invalid #enderror" name="name" value="{{ old('name') }}" required autocomplete="name" autofocus>
#error('gebruikersnaam')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control #error('email') is-invalid #enderror" name="email" value="{{ old('email') }}" required autocomplete="email">
#error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="voornaam" class="col-md-4 col-form-label text-md-right">{{ __('Voornaam') }}</label>
<div class="col-md-6">
<input id="voornaam" type="text" class="form-control #error('voornaam') is-invalid #enderror" name="voornaam" value="{{ old('voornaam') }}" required autocomplete="voornaam">
#error('voornaam')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="achternaam" class="col-md-4 col-form-label text-md-right">{{ __('Achternaam') }}</label>
<div class="col-md-6">
<input id="achternaam" type="text" class="form-control #error('achternaam') is-invalid #enderror" name="achternaam" value="{{ old('achternaam') }}" required autocomplete="achternaam">
#error('achternaam')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="telefoonnummer" class="col-md-4 col-form-label text-md-right">{{ __('Telefoonnummer') }}</label>
<div class="col-md-6">
<input id="telefoonnummer" type="text" class="form-control #error('telefoonnummer') is-invalid #enderror" name="telefoonnummer" value="{{ old('telefoonnummer') }}" required autocomplete="telefoonnummer">
#error('telefoonnummer')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="wachtwoord" class="col-md-4 col-form-label text-md-right">{{ __('Wachtwoord') }}</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>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</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 mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Registreer') }}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
The expected thing to happen is that i can register and actually save in the database and logging in.
The output at the moment is the opposite.

Categories