Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
165 views
in Technique[技术] by (71.8m points)

laravel - Class AppHttpControllersPostConstroller does not exist

Hello I try to create post with Laravel, but I have this error :

Class AppHttpControllersPostConstroller does not exist

Route:

Route::get('/', function () {
    return view('welcome');
});

Auth::routes(['verify' => true]);

Route::get('/home', 'HomeController@index')->name('home');
Route::get('/profile/{user}', 'ProfileController@show')->name('profile.show');
Route::get('/posts/create', 'PostConstroller@create')->name('posts.create');
Route::post('/posts', 'PostConstroller@store')->name('posts.store');

Controller:

<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;

class PostController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }

    public function create()
    {
        return view('posts.create');
    }
}

Model:

<?php

namespace App;

use IlluminateDatabaseEloquentModel;

class Post extends Model
{
    public function user()
    {
        return $this->belongsTo('AppUser');
    }
}

and I can do for leave this error?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Hey you didn't notice you have spelling mistake in your import it should be PostController not PostConstroller

Change this

AppHttpControllersPostConstroller

to

AppHttpControllersPostController

and yes same issue is with your routes:

Route::get('/posts/create', 'PostConstroller@create')->name('posts.create');
Route::post('/posts', 'PostConstroller@store')->name('posts.store');

Change your routes to:

Route::get('/posts/create', 'PostController@create')->name('posts.create'); 
Route::post('/posts', 'PostController@store')->name('posts.store');

Thanks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...