You can probably see Im very new to laravel. I have ran into an issue where it cant seem to see the new class I've made...
Firstly I ran....
php artisan make:request CreateSongRequest
which in turn generated a CreateSongRequest.php file in app/Http/Requests/
The contents...
<?php namespace App\Http\Requests;
use App\Http\Requests\Request;
class CreateSongRequest extends Request {
/**
* 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 [
//
];
}
}
In my controller I have the form post to the following method...
public function store(CreateSongRequest $request, Song $song) {
$song->create($request->all());
return redirect()->route('songs_path');
}
When I submit the form, Im getting the following error...
ReflectionException in RouteDependencyResolverTrait.php line 53: Class App\Http\Controllers\CreateSongRequest does not exist
When Laravel generates a redirect response due to a validation error, the framework will automatically flash all of the request's input to the session. This is done so that you may conveniently access the input during the next request and repopulate the form that the user attempted to submit.
Each form request generated by Laravel has two methods: authorize and rules. As you might have guessed, the authorize method is responsible for determining if the currently authenticated user can perform the action represented by the request, while the rules method returns the validation rules that should apply to the request's data:
Since ProductUpdateRequest inherits from FormRequest, Laravel will know to inject the class as the $request parameter as well as run the authorize and validation logic before hand. If the validation fails, Laravel will return the user to the form with the errors.
Laravel does an incredible job helping developers break their code into smaller parts, which reduces code clutter and makes the code easier to read. I recently discovered how to create a custom form request for handling validation during a form submission. Let’s pretend we have created a Product model and want to update the name or price fields.
You need to add this at the top of your controller:
use App\Http\Requests\CreateSongRequest;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With