Maybe you need to run:
composer dump-autoload
Im getting this error and i have previously defined the class on the controller and also on the http requests and i'm still getting this error, i really don't kow what do to, im stuck
Maybe you need to run:
composer dump-autoload
I've been running dump-autoload and still nothing
Show some code.
namespace App\Http\Controllers;
use App\Client;
use Illuminate\Http\Requests;
use App\Http\Requests\SaveClientRequest;
namespace App\Http\Requests;
use Illuminate\Validation\Rule;
use Illuminate\Foundation\Http\FormRequest;
class SaveClientRequest extends FormRequest
Route::resource('clients', 'ClientsController')
->parameters(['clientes' => 'client'])
->names('clients');
I have created all with the artisan commands
A weird thing was that i tried to use another class that actually works but using different data and the same error appeared "ReflectionException Class App\Http\Requests\SaveProjectRequest does not exist"
You can notice that i changed the file there and the error is the same
Have you made sure that route is hitting that controller by using a dd or an echo.
Tell us WHAT file you get the error in and WHAT you were doing at the time.
Please format your code by putting 3 backticks ``` on a line before and after each code block
Didn't try that yet, but the route source is working because i just can't insert or update the data
I got the error in this file
use App\Http\Requests\SaveClientRequest;
So the class is created here
namespace App\Http\Requests;
use Illuminate\Validation\Rule;
use Illuminate\Foundation\Http\FormRequest;
class SaveClientRequest extends FormRequest
I'm also using the class on the controller
public function store(SaveClientRequest $request)
{
Client::create($request->validated() );
return redirect()->route('clients.index')->with('status','El cliente fue creado con éxito');
}
And
public function update(Client $Client, SaveClientRequest $request)
{
$client->update($request->validated() );
return redirect()->route('clients.show', $project)->with('status','El Cliente fue actualizado con éxito');
}
My composer.json file is like this
"autoload": {
"psr-4": {
"App\": "app/"
},
And the Route::source
Route::resource('clients', 'ClientsController')
->parameters(['clientes' => 'client'])
->names('clients');
So basically i can't add or update using the "SaveClienteRequest" which is a FormRequest
A weird problem is that i tried with another FormRequest that is actually working (insert and update works great there) so i just changed the paremeters and i got the same error "ReflectionException Class App\Http\Requests\SaveProjectRequest does not exist" you can notice that the class is different here and this class is working perfectly in another controller.
Pd: Sorry for not using the format code before.
My guess is that you have a syntax error in the SaveClientRequest file, or the name of the file isn't SaveClientRequest.php
A syntax error means a missing ; or }. If you post the full code for it, we can check
Full syntax of SaveClientRequest
<?php
namespace App\Http\Requests;
use Illuminate\Validation\Rule;
use Illuminate\Foundation\Http\FormRequest;
class SaveClientRequest extends FormRequest
{
public function authorize()
{
return true;
}
public function rules()
{
return [
'dui' -> ['required', Rule::unique('clients')->ignore( $this->route('client') )
],
'nombre' -> 'required',
'apellido' -> 'required',
'direccion' -> 'required',
'telefono' -> 'required'
];
}
public function message()
{
return [
'dui.required' => 'El cliente necesita un dui',
'nombre.required' => 'El cliente necesita un nombre',
'apellido.required' => 'El cliente necesita un apellido',
'direccion.required' => 'El cliente necesita una dirección',
'telefono.required' => 'El cliente necesita un teléfono'
];
}
}
Looks good. And the path + filename to the file? app/Http..?
This is the path
use App\Http\Requests\SaveClientRequest;
I am talking about the actual filename and path on the computer (from root directory of laravel)
C:\laragon\www\laravel\app\Http\Requests\SaveClientRequest.php
Where i also have the other class that is working
C:\laragon\www\laravel\app\Http\Requests\SaveProjectRequest.php
I went to the laravel.log after the error and i found this
[2020-02-27 16:06:26] local.ERROR: Class App\Http\Requests\SaveClientRequest does not exist {"userId":1,"exception":"[object] (ReflectionException(code: 0): Class App\Http\Requests\SaveClientRequest does not exist at C:\laragon\www\laravel\vendor\laravel\framework\src\Illuminate\Routing\RouteSignatureParameters.php:25)
[stacktrace]
After making this file, you did run
composer dumpautoload
I don't see a mis-spelling anywhere.
Still getting this error
ReflectionException Class App\Http\Requests\SaveClientRequest does not exist
And yes i run that command after creation of the file, actually both, the controller and the class
@sinnbeck is correct. You have a syntax error on your file. @pier67 please rewrite your rules() function. you are using -> instead of =>.
public function rules()
{
return [
'dui' => ['required', Rule::unique('clients')->ignore( $this->route('client') )
],
'nombre' => 'required',
'apellido' => 'required',
'direccion' => 'required',
'telefono' => 'required'
];
}
Hope this works.
@ajithlal nice catch. Didn't have a code editor (IDE) to test with, only my eyes. A good reason to use an IDE when coding
Thank you so much it works now!
@pier67 Consider using an IDE like visual studio code. Here is your code in that program, and as you can see it clearly marks the errors.
@sinnbeck thanks mate.
Thanks for the recommendation!
guys I know it´s been a long time since the error happened, but this is a way I found to solve the issue
"Route::apiResource('contactos', \App\Http\Controllers\ContactoController::class);"
I just added the complete route of my controller in the api.php
Please or to participate in this conversation.