validation error regarding the validation file in laravel - laravel

I am calling a validation request but i am getting this error.
Method Illuminate\Validation\Validator::validateFile, does not exist.
My UserRequest
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use App\Http\Controllers\ProfileController;
class UserRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* #return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* #return array
*/
public function rules()
{
return [
'name'=> 'string|required|max:255',
'username'=> 'string|required|max:255|alpha_dash',
'avatar'=>'file,|mimes:jpeg,png,gif,jpg|max:2048',
'email'=> 'email|required|string',
'password'=>'required|min:10|string|confirmed',
'background'=>'file,|mimes:jpeg,png,gif,jpg|max:2048',
'description'=>'string|max:255'
];
}
public function messages()
{
return [
'name.required' => 'A name is required',
'username.required' => 'A username is required',
'email.required' => 'An email is required',
'password.required' => 'A password is required',
'description' => 'A description should be string',
];
}
}
My Controller
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests\UserRequest;
use Illuminate\Http\File ;
use App\User;
use Hash;
use Session;
public function update(User $user,UserRequest $request)
{
$user->update(['name'=>request('name'),'username'=>request('username'),'email'=>request('email'),'password'=> Hash::make(request('password')),'avatar'=>$path,'background'=>$background,'description'=>request('description')]);
Session::flash('success', 'You have successfully updated a post!');
return redirect($user->path())->with(['message'=>'Profile updated']);
}
my blade
#extends('layouts.app')
#section('content')
<h1 class="text-gray-700 text-2xl font-bold text-center">Edit Profile</h1>
<div class="mt-5 mb-6">
<img src="{{$user->avatar()}}" alt=""
class="rounded-full mr-2 bottom-0 transform "
width="150px" style="transform: translateX(16.5rem);" >
</div>
<form method="POST" action="{{$user->path() }}" enctype="multipart/form-data">
#csrf
#method('PATCH')
<div id="flip" class="p-5 bg-gray-200">Basic Info</div>
<div id="panel">
<div class="mb-6 mt-6">
<label for="avatar">Select Profile to Upload</label>
<input id="avatar" type="file" class="#error('avatar') is-invalid #enderror" name="avatar">
#error('avatar')
<div class="text-red-800">{{ $message }}</div>
#enderror
</div>
<div class="mb-6">
<label for="name">Name</label>
<input id="name" type="text" class="#error('name') is-invalid #enderror border border-gray-400 p-2 w-full" name="name" value="{{$user->name}}">
#error('name')
<div class="text-red-800">{{ $message }}</div>
#enderror
</div>
<div class="mb-6">
<label for="username">Username</label>
<input id="username" type="text" name="username" class="#error('username') is-invalid #enderror border border-gray-400 p-2 w-full" value="{{$user->username}}">
#error('username')
<div class="text-red-800">{{ $message }}</div>
#enderror
</div>
<div class="mb-6">
<label for="email">Email</label>
<input id="email" type="email" name="email" class="#error('email') is-invalid #enderror border border-gray-400 p-2 w-full" value="{{$user->email}}">
#error('email')
<div class="text-red-800">{{ $message }}</div>
#enderror
</div>
<div class="mb-6">
<label for="password">Password</label>
<input id="password" type="password" name="password" class="#error('password') is-invalid #enderror border border-gray-400 p-2 w-full" >
#error('password')
<div class="text-red-800">{{ $message }}</div>
#enderror
</div>
<div class="mb-6">
<label for="password-confirm">Confirm Password</label>
<input id="password-confirm" type="password" name="password-confirm" class="#error('password-confirm') is-invalid #enderror border border-gray-400 p-2 w-full" >
#error('password-confirm')
<div class="text-red-800">{{ $message }}</div>
#enderror
</div>
</div>
<div id="main" class="p-5 bg-gray-200">Background</div>
<div id="child">
<div class="mb-6 mt-6">
<label for="background">Select Background image to Upload</label>
<input id="background" type="file" class="#error('background') is-invalid #enderror" name="background">
#error('background')
<div class="alert alert-danger">{{ $message }}</div>
#enderror
</div>
<div class="mb-6">
<label for="description">Description</label>
<input id="description" type="text" name="description" class="#error('description') is-invalid #enderror border border-gray-400 p-2 w-full" value="{{$user->description}}">
#error('description')
<div class="alert alert-danger">{{ $message }}</div>
#enderror
</div>
</div>
<div class="mt-6">
<button type="submit" class="bg-blue-500 text-white rounded py-2 px-4 hover:bg-blue-800'">Submit</button>
</div>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#flip").click(function(){
$("#panel").slideToggle("slow");
});
$("#main").click(function(){
$("#child").slideToggle("slow");
});
});
</script>
#endsection
I have tried the solutions available on stack overflow but still none of them work
Does anyone know why am i getting this error?
Any help will be appreciated.

Remove comma in these validation lines.
'avatar'=>'file,|mimes:jpeg,png,gif,jpg|max:2048',
'background'=>'file,|mimes:jpeg,png,gif,jpg|max:2048',

Add password.confirmed in messages array.
'password.confirmed' => 'YOUR ERROR MESSAGE',

Related

Laravel 8 How to restrict user login if email is not verified

I am using Bootstrap Starter template package in Laravel 8 that replaces Tailwind CSS framework with Bootstrap CSS framework.
https://packagist.org/packages/shahvirag/laravel-ui-bootstrap
The problem I'm having is that user can sign in after registration without needing to verify account through email. How can I restrict his access until the email is not verified?
I have followed the steps and tried using routes middleware, but there is no such file in App\Http\Controllers\PagesController;
Route::get('/',[PagesController::class, 'index'])->name('users')->middleware('verified'); // this does not work
Any help?
routes/web.php
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PagesController;
Route::get('/', function () {
return view('main');
});
Route::middleware(['auth'])->group(function() {
Route::get('/home', function() {
return view('home');
})->name('home');
Route::get('/user/profile', function() {
return view('profile');
})->name('profile');
});
Route::get('/',[PagesController::class, 'index'])->name('users')->middleware('verified');
resources/views/auth/login.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">{{ __('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
To use verified middleware, your user model should implement MustVerifyEmail
class User extends Authenticatable implements MustVerifyEmail
{
use Notifiable;
// ...
}
Try this instead
Route::get('/',[PagesController::class, 'index'])->name('users')->middleware(['auth', 'verified']);
You can use the method included with the User model:
$user->hasVerifiedEmail()
Or in the routes middleware(['verified'])

how to validate Unique database field on Controller in laravel

Good Day, I am new in Laravel environment. I am developing a simple school enrollment registration website but having trouble in validation on my controller..
My plan is, when the user will register in the website, username textbox should be validated if the username is already used by other student. i tried every possible tutorial i found in the net but i have no luck...
Here is my page, red circle should be validated if the input username already exist in the database..
Whole code in .blade
<!--Registration start here -->
<form method="Post" action="{{url('store_account_Registration')}}">
#csrf
#if(Session::get('success'))
<div class="alert alert-danger">
{{ Session::get('success')}}
</div>
#endif
#if(Session::get('fail'))
<div class="alert alert-danger">
{{ Session::get('fail')}}
</div>
#endif
<div class="col-sm-12 form-group">
<input type="hidden" class="form-control" name="uniqID3" id="uid" placeholder="Enrollment Registration Number" value="{{ $regid3 }}" >
</div>
<div class="col-sm-12 form-group">
<input type="hidden" class="form-control" name="pfulname3" id="name-f" placeholder="Enrollment Registration Number" required value="{{ $fulname4 }}" >
</div>
<div class="container-fluid" style="margin-bottom: 2em">
<div class="row justify-content-center align-items-center" style="padding: 10px">
<div class="card col-md-5" style="transform: none;>
<div class="card-body">
<div class="alert alert-primary" role="alert" style="margin-top: 1em">
<p>Name: <strong>{{ $fulname4 }}</strong></p>
<p>Enrollment No.: <strong>{{ $regid3 }}</strong></p>
</div>
<input type="hidden" class="hide" id="csrf_token" name="csrf_token" value="C8nPqbqTxzcML7Hw0jLRu41ry5b9a10a0e2bc2">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Username</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-user" aria-hidden="true"></i></span>
</div>
<input type="text" class="form-control" name="username" id="username" placeholder="Username" required value="{{ old('username')}}" >
</div>
<div class="help-block with-errors text-danger">
<span style="color:red">#error('username'){{ $message}}#enderror</span>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Password</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-lock" aria-hidden="true"></i></span>
</div>
<input type="password" id="password" name="password" pattern="^\S{6,}$" onchange="this.setCustomValidity(this.validity.patternMismatch ? 'Must have at least 6 characters' : ''); if(this.checkValidity()) form.password_two.pattern = this.value;" class="form-control" title="Password is needed" required placeholder="Password" >
</div>
<div class="help-block with-errors text-danger">
<span style="color:red">#error('password'){{ $message}}#enderror</span>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Confirm Password</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-lock" aria-hidden="true"></i></span>
</div>
<input id="password_two" type="password" name="password_two" pattern="^\S{6,}$" onchange="this.setCustomValidity(this.validity.patternMismatch ? 'Please enter the same Password as above' : '');" placeholder="Confirm Password" class="form-control" title="Confirm Password is needed" required placeholder="Confirm Password" >
</div>
<div class="help-block with-errors text-danger">
<span style="color:red">#error('password_two'){{ $message}}#enderror</span>
</div>
</div>
</div>
</div>
<div class="row" style="margin-top: 1em" >
<div class="col-md-12" style="margin-bottom: 2em">
<input type="hidden" name="redirect" value="">
<!-- <button type="submit" class="btn btn-primary btn-lg btn-block" name="submit">Save OASIS Account</button> -->
<!-- < <p class="btn btn-primary btn-lg btn-block">Save OASIS Account</p> -->
<button type="submit" class="btn btn-primary btn-lg btn-block">Save OASIS Account</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!--Registration start here -->
</div>
</form>
enter code here
I always got this error..
Here is my code..
my validation in my controller
public function store_account_Registration(Request $request)
{
request()->validate([
'username' => 'required|min:6|unique:TempAccount,AccountName,'
]);
// $this->validator($request->all())->validate();
$current_date = date('Y-m-d H:i:s');
$query = DB::table('TempAccount')->insert([
'RegID'=>$request->input('uniqID3'),
'FullName'=>$request->input('pfulname3'),
'AccountName'=>$request->input('username'),
'Pass'=>$request->input('password'),
'created_at'=> $current_date,
'updated_at'=> $current_date,
]);
if($query){
return back()->with('success', 'Data has been Successfyll inserted');
// return view('pages.enrollment_success');
// return redirect()->route('pages.enrollment_GradeLevelSchoolInfo', ['uniqIDd' => 1]);
// return redirect('enrollment_GradeLevelSchoolInfo');
}
else
{
return back()->with('fail', 'something went wrong');
}
}
my Route in web.php
Route::get('pages',[accountregistration::class, 'index']);
Route::Post('store_account_Registration', [accountregistration::class, 'store_account_Registration']);
my action in form..
The issue is in your form. You are not reaching the correct route at all.
Also you are missing the #csrf token or at least not shown in your print screen
<form action="{{url('store_account_Registration')}}" method="POST">
#csrf
In your validation you can remove the trailing coma after AccountName as well.

Error: 405 - Method not allowed while trying to update in Laravel

Current, I am working on a project using Laravel-5.8. I have a code to update data:
Controller
public function store_external_respondent(StoreAppraisalRespondentExternalRequest $request)
{
$userCompany = Auth::user()->company_id;
$userEmployee = Auth::user()->employee_id;
DB::beginTransaction();
try {
$respondent = AppraisalRespondent::create([
'fullname' => $request->fullname,
'respondent_email' => $request->respondent_email,
'company_name' => $request->company_name,
'is_internal' => 1,
]);
DB::commit();
Session::flash('success', 'Appraisal Respondent created successfully');
return redirect()->route('appraisal.appraisal_respondents.index');
} catch (Exception $ex) {
DB::rollback();
Session::flash('error', 'Action failed! Please try again');
return back();
}
}
route/web.php:
Route::group(['prefix' => 'appraisal', 'as' => 'appraisal.', 'namespace' => 'Appraisal', 'middleware' => ['auth']], function () {
Route::post('appraisal/appraisal_respondents/update_external_respondent/{id?}', 'AppraisalRespondentsController#update_external_respondent')->name('appraisal_respondents.update_external_respondent');
});
When I did php artisan route:list, I got:
| | POST | appraisal/appraisal/appraisal_respondents/update_external_respondent/{id?} | appraisal.appraisal_respondents.update_external_respondent | App\Http\Controllers\Appraisal\AppraisalRespondentsController#update_external_respondent | web,auth
update view blade
<button type="button" class="btn btn-sm btn-info mr-1 edit-respondent-respondent" data-toggle="modal" data-target="#edit_respondent_external{{ $respondentexternal->id }}">Edit</button>
<div class="modal fade" id="edit_respondent_external{{ $respondentexternal->id }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form action="{{route('appraisal.appraisal_respondents.update_external_respondent',['id'=>$respondentexternal->id])}}" method="post" id="edit_respondent-external-form">
{{ csrf_field() }}
<input type="hidden" name="appraisal_identity_id" value="{{$identities->id}}">
<input type="hidden" name="employee_id" value="{{$employees->id}}">
<input name="_method" type="hidden" value="PUT">
<div class="modal-header">
Update Respondent (External)
</div>
<div class="col-md-12">
<div class="form-group">
<label class="control-label"> FullName:<span style="color:red;">*</span></label>
<input type="text" name="fullname" placeholder="Enter external respondent fullname here" class="form-control" value="{{old('fullname',$respondentexternal->fullname)}}">
#error('fullname')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label class="control-label"> Company:<span style="color:red;">*</span></label>
<input type="text" name="company_name" placeholder="Enter external respondent company here" class="form-control" value="{{old('company_name',$respondentexternal->company_name)}}">
#error('company_name')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label class="control-label"> Respondent Email:<span style="color:red;">*</span></label>
<input type="text" name="respondent_email" placeholder="Enter external respondent email here" class="form-control" value="{{old('respondent_email',$respondentexternal->respondent_email)}}">
#error('respondent_email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="submit" id="edit_respondent_external_btn-submit" class="btn btn-success btn-ok">Save</button>
</div>
</form>
</div>
</div>
</div>
When I submitted, I got this error:
405
Method Not Allowed.
Sorry, the page you are looking for could not be found. Go Back
In the console I have:
POST http://localhost:8888/myapp/appraisal/appraisal/appraisal_respondents/update_external_respondent/2 405 (Method Not Allowed)
How do I resolve this?
Also Why is appraisal repeated twice in
POST http://localhost:8888/myapp/appraisal/appraisal/appraisal_respondents/update_external_respondent/2 405 (Method Not Allowed)
Thanks
// STEP 1
Route::post('appra....
// STEP 2
<input name="_method" type="hidden" value="PUT">
So what's wrong?
please use {{method_field('check_your_route_type')}} below {{ csrf_field() }}
e.g : Route::put('url' ... should use {{method_field('PUT')}}

Route [/admin/update-pwd] not defined

I am trying to change the admin password but it says: Route [/admin/update-pwd] not defined. How do I change it?
controller:
public function changepassword()
{
return view('admin.changepassword');
}
public function chkPassword(Request $request){
$data = $request->all();
$adminCount = Admin::where(['username' => Session::get('adminSession'),'password'=>md5($data['current_pwd'])])->count();
if ($adminCount == 1) {
echo "true"; die;
} else {
echo "false"; die;
}
}
public function updatePassword(Request $request){
if($request->isMethod('post')){
$data = $request->all();
$adminCount = Admin::where(['username' => Session::get('adminSession'),'password'=>md5($data['current_pwd'])])->count();
if ($adminCount == 1) {
$password = md5($data['new_pwd']);
Admin::where('username',Session::get('adminSession'))->update(['password'=>$password]);
return redirect('/admin/settings')->with('flash_message_success', 'Password updated successfully.');
}else{
return redirect('/admin/settings')->with('flash_message_error', 'Current Password entered is incorrect.');
}
}
}
blade file:
<form method="POST" action="{{ route('/admin/update-pwd') }}" enctype="multipart/form-data">
#csrf
#method('PATCH')
<strong class="text-muted d-block mb-2">Enter Current Password</strong>
<div class="input-group mb-3">
<div class="input-group input-group-seamless">
<input type="password" name="current_pwd" class="form-control #error('password') is-invalid #enderror" id="form2-password" placeholder="Password">
<span class="input-group-append">
<span class="input-group-text">
<i class="material-icons">lock</i>
</span>
</span>
</div>
</div>
<strong class="text-muted d-block mb-2">Enter New Password</strong>
<div class="input-group mb-3">
<div class="input-group input-group-seamless">
<input type="password" name="new_pwd" class="form-control #error('password') is-invalid #enderror" id="form2-password" placeholder="Password">
<span class="input-group-append">
<span class="input-group-text">
<i class="material-icons">lock</i>
</span>
</span>
</div>
</div>
<strong class="text-muted d-block mb-2">Confirm New Password</strong>
<div class="input-group mb-3">
<div class="input-group input-group-seamless">
<input type="password" name="confirm_pwd" class="form-control #error('password') is-invalid #enderror" id="form2-password" placeholder="Password">
<span class="input-group-append">
<span class="input-group-text">
<i class="material-icons">lock</i>
</span>
</span>
</div>
</div>
#error('password')
<div class="small text-danger">{{ $message }}</div>
#enderror
<button type="submit" class="mb-2 btn btn-primary mr-2">Update Password</button>
</form>
Routes:
Route::get('/admin/changepassword', 'ChangepasswordController#changepassword');
Route::get('/admin/check-pwd','AdminController#chkPassword');
Route::match(['get', 'post'],'/admin/update-pwd','AdminController#updatePassword');
When you use the route helper it expects that you provide a route name not a URI, so add this:
Route::match(['get', 'post'],'/admin/update-pwd','AdminController#updatePassword')
->name('admin.update_password');
Then in your view you can use:
route('admin.update_password');
Or use the url helper method instead:
// instead of this
{{ route('/admin/update-pwd') }}
//use
{{ url('/admin/update-pwd') }}
You are trying to use Laravel named route inside your form method. Use Laravel Named Routed, and define it inside your form.
//inside web.php
Route::post('/admin/update-pwd','AdminController#updatePassword')->name('admin/update-pwd');
Then you will be able to use inside form
<form method="POST" action="{{ route('/admin/update-pwd') }}" enctype="multipart/form-data">

Add [title] to fillable property to allow mass assignment on [App\Profile]

I am trying to create edit profile, but when I click on edit profile button I'm getting below error:
Illuminate \ Database \ Eloquent \ MassAssignmentException Add [title]
to fillable property to allow mass assignment on [App\Profile]
show.blade.php :
<#extends('layouts.app')
#section('content')
<div class="container">
<div class="row">
<div class="col-4">
<img src="https://scontent-cdt1-1.cdninstagram.com/vp/dcca3b442819fc8b9b63f09b2ebde320/5DA9E3CB/t51.2885-19/s150x150/40101184_290824334847414_1758201800999043072_n.jpg?_nc_ht=scontent-cdt1-1.cdninstagram.com" class="rounded-circle">
</div>
<div class="col-8">
<div class="d-flex align-items-baseline">
<div class="h4 mr-3 pt-2">{{ $user->username }}</div>
<button class="btn btn-primary">S'abonner</button>
</div>
<div class="d-flex">
<div class="mr-3">{{ $user->posts->count() }} article(s) en vente
</div>
Modifier Profile
<div class="mt-3">
<div class="font-weight-bold">
{{ $user->profile->title }}
</div>
<div class="font-weight-bold">
{{ $user->profile->description }}
</div>
</div>
</div>
</div>
<div class="row mt-5">
#foreach ($user->posts as $post)
<div class="col-4">
<img src="{{ asset('storage') . '/' . $post->image }}" class="w-100">
</div>
#endforeach
</div>
</div>
#endsection
ProfileController :
<?php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
class ProfileController extends Controller
{
public function show(User $user)
{
return view('profile.show', compact('user'));
}
public function edit(User $user)
{
return view('profile.edit', compact('user'));
}
public function update(User $user)
{
$data = request()->validate([
'title' => 'required',
'description' => 'required'
]);
$user->profile->update($data);
return redirect()->route('profile.show', ['user' => $user]);
}
}
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">Modifier profile</div>
<div class="card-body">
<form method="POST" action="{{ route('profile.update', ['user' => $user]) }}" enctype="multipart/form-data">
#csrf
#method('PATCH')
<div class="form-group">
<label for="title">Titre</label>
<div class="col-md-6">
<input id="title" type="text" class="form-control #error('title') is-invalid #enderror" name="title" value="{{ old('title') ?? $user->profile->title }}" autocomplete="title" autofocus>
#error('title')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group">
<label for="description">Description</label>
<div class="col-md-6">
<textarea id="description" type="text" class="form-control #error('description') is-invalid #enderror" name="description" autocomplete="description" autofocus>{{ old('description') ?? $user->profile->description }}</textarea>
#error('description')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group">
<div class="custom-file">
<input type="file" name="image" class="custom-file-input #error('image') is-invalid #enderror" id="validatedCustomFile" >
<label class="custom-file-label" for="validatedCustomFile">Choisir une image</label>
#error('image')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
Modifier profile
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
Profile.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Profile extends Model
{
protected $guarder = [];
public function user()
{
return $this->belongsTo('App\User');
}
}
What am I doing wrong here and how can I get rid of this error?
You have a spelling error, instead of $guarder add this in your model:
protected $guarded = [];
I won't advise using empty guarded but use $fillable instead.
In the same controller model, free access to database fields with
protected $guarded = [];
or
protected $fillable = [];

Resources