App \ Http \ Controllers \ PostConstroller类不存在

时间:2019-07-13 12:14:27

标签: laravel class laravel-5.8

您好,我尝试使用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');
    }
}

我可以做这个错误吗?

1 个答案:

答案 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');

谢谢