本文介绍了类App \ Http \ Controllers \ PostConstroller不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我尝试使用Laravel创建帖子,但出现此错误:
Hello I try to create post with Laravel, but I have this error :
路线:
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');
}
}
我可以为这个错误做些什么吗?
and I can do for leave this error?
推荐答案
嘿,您在导入时没有发现拼写错误,应该是PostController
而不是PostConstroller
Hey you didn't notice you have spelling mistake in your import it should be PostController
not PostConstroller
更改此
App\Http\Controllers\PostConstroller
到
App\Http\Controllers\PostController
是的,您的路线也有同样的问题:
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');
将路线更改为:
Route::get('/posts/create', 'PostController@create')->name('posts.create');
Route::post('/posts', 'PostController@store')->name('posts.store');
谢谢
这篇关于类App \ Http \ Controllers \ PostConstroller不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!