1
votes

I'm using laravel 5.6 and in my PostController I'm trying to change this:

public function store(Request $request)
    {
    $post = new PostRepository();
    $post->body = $request->input('body');
    $post->user_id = $request->input('user_id');
    $post->save();
    return redirect('home');
}

to this:

public function store()
{
    PostRepository::create(Input::all());

    return redirect('home');
}

but I get an error: 'ReflectionException in Route.php line 280: Class App\Http\Controllers\PostController does not exist'.

The former works but the latter does not. I've seen other answers to this error but none works for me. I've compared spelling of my controller with what I have in routes.php, also namespaces, those are fine.

This is my routes.php file:

Route::group(['middleware' => ['web']], function () {
    Route::get('/', 'PostController@index');
    Route::post('/home', 'PostController@store');
});
1
It works fine until you change what is inside the store method?Giovanni S
Yes. I'm following a Laracast tutorial introducing laravel. I just replaced what I had with what I saw in the tutorial in my controller file. Maybe I'm missing something with Eloquent.Pedro P. Camellón Q.
Try this answer. composer dumpautoload.ourmandave
Yeah....composer dump-autoload -o should fix it.Chukwuemeka Inya
It worked !! After 'composer dumpautoload', I received an error with the Input class (I forgot to import it). Thanks a lot :DPedro P. Camellón Q.

1 Answers

1
votes

Running "composer dump-autoload -o" solved this issue.