am working on a laravel project and I am working on a user update profile, I am getting an error when updating and I can't figure out the solution.
below is the error I am getting
Target class [App\Http\Controllers\UpdateProfileRequest] does not exist.
below is my route in web.php
Route::get('users/edit', 'UserController@edit')->name('users.edit');
Route::put('users/update', 'UserController@update')->name('users.update');
below is UserController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
class UserController extends Controller
{
//
public function edit()
{
return view('users.edit')->with('user', auth()->user());
}
public function update(UpdateProfileRequest $request)
{
$user = auth()->user();
$user->update([
'name' => $request->name,
'organization' => $request->organization,
'email' => $request->email,
'password' => $request->password
]);
return redirect()->back;
}
}
below is my UpdateProfileRequest
<?php
namespace App\Http\Requests\User;
use Illuminate\Foundation\Http\FormRequest;
class UpdateProfileRequest 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'=>'required',
'organization'=>'required',
'email'=>'required',
'password'=>'required'
];
}
}
below is the edit.blade.php view
@extends('layouts.app')
@section('content')
<div >
<div >
<div >
<p ><img src="{{ asset('img/logo1.jpg') }}" width="60" height="50" alt="logo1"></p>
<hr style="width:50%", size="2", color=3490dc>
<div >
<div style="text-align: center; background-color:#3490dc; color:white;" ><i aria-hidden="true"></i> {{ __('My Profile') }}</div>
<div >
<form method="POST" action="{{ route('users.update') }}">
@csrf
@method('PUT')
<div >
<label for="name" ><i style="color:#3490dc;"></i> {{ __('Name') }}</label>
<div >
<input id="name" type="text" name="name" value="{{ $user->name }}" required autocomplete="name" autofocus>
</div>
</div>
<div >
<label for="organization" ><i style="color:#3490dc;"></i> {{ __('Organization') }}</label>
<div >
<input id="organization" type="text" name="organization" value="{{ $user->organization }}" required autocomplete="organization" autofocus>
</div>
</div>
<div >
<label for="email" ><i style="color:#3490dc;"></i> {{ __('E-Mail Address') }}</label>
<div >
<input id="email" type="email" name="email" value="{{ $user->name }}" required autocomplete="email">
</div>
</div>
<div >
<label for="password" ><i style="color:#3490dc;"></i> {{ __('Password') }}</label>
<div >
<input id="password" type="password" name="password" required autocomplete="new-password">
</div>
</div>
<div >
<label for="password-confirm" ><i style="color:#3490dc;"></i> {{ __('Confirm Password') }}</label>
<div >
<input id="password-confirm" type="password" name="password_confirmation" required autocomplete="new-password">
</div>
</div>
<div >
<div >
<button type="submit" >
{{ __('Update') }}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<br/>
@include('footer')
@endsection
below is the link to the view in app.blade.php
<a href="{{ route('users.edit') }}"
>
{{ __('My Profile') }}
</a>
<form id="edit-form" action="{{ route('users.edit') }}" style="display: none;">
@csrf
</form>
I will appreciate any help thanks in advance
CodePudding user response:
You're missing a using.
Add use UpdateProfileRequest;
at the top.
(this might not be the correct path, try hovering UpdateProfileRequest
and looking for an Import class
button)
CodePudding user response:
You must use it on top of UserController
class:
use App\Http\Requests\UpdateProfileRequest;