您好,我尝试使用Laravel创建帖子,但出现此错误:
App \ Http \ Controllers \ PostConstroller类不存在
路线:
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');
控制器:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PostController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function create()
{
return view('posts.create');
}
}
型号:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
public function user()
{
return $this->belongsTo('App\User');
}
}
我可以做这个错误吗?
答案 0 :(得分:4)
嘿,您在导入时没有发现拼写错误,应该是PostController
而不是PostConstroller
更改此
App\Http\Controllers\PostConstroller
到
App\Http\Controllers\PostController
是的,您的路线也有同样的问题:
Route::get('/posts/create', 'PostConstroller@create')->name('posts.create');
Route::post('/posts', 'PostConstroller@store')->name('posts.store');
将路线更改为:
Route::get('/posts/create', 'PostController@create')->name('posts.create');
Route::post('/posts', 'PostController@store')->name('posts.store');
谢谢