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');
});
composer dumpautoload
. – ourmandavecomposer dump-autoload -o
should fix it. – Chukwuemeka Inya