Laravel create request does not work

You can probably see that Im very new to laravel. I ran into a problem in which it does not seem to see the new class that I created ...

First, I ran ....

php artisan make:request CreateSongRequest 

which, in turn, generated the CreateSongRequest.php file in the application / Http / Requests /

Content...

 <?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 a form message for 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 on line RouteDependencyResolverTrait.php 53: Application of class \ Http \ Controllers \ CreateSongRequest does not exist

+6
source share
2 answers

You need to add this at the top of your controller:

 use App\Http\Requests\CreateSongRequest; 
+9
source

Try this .. It works ..

 public function store(Request $request, Song $song) { $this->validate($request, [ 'title' => 'required', 'slug' => 'required|unique:songs,slug', ]); $song->create($request->all()); return redirect()->route('songs_path'); } 

Source: http://laravel.com/docs/5.1/validation

0
source

Source: https://habr.com/ru/post/983916/


All Articles