Adrian
Adrian

Reputation: 2012

laravel create request not working

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

Upvotes: 6

Views: 11770

Answers (2)

Ridwan Pujakesuma
Ridwan Pujakesuma

Reputation: 1066

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

Upvotes: 0

JoeCoder
JoeCoder

Reputation: 880

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

use App\Http\Requests\CreateSongRequest;

Upvotes: 9

Related Questions