Php 类别';App/Post&x27;未在laravel-5.6中找到
当我在做我的laravel项目时,我犯了这个错误,即使经过这么多的改变和努力,我也无法解决它。我希望我能找到一些解决办法 我的错误: Symfony\Component\Debug\Exception\fatalthrowable错误与一起引发 消息“类”应用程序/帖子“未找到” CommentsController.phpPhp 类别';App/Post&x27;未在laravel-5.6中找到,php,laravel,laravel-5.6,Php,Laravel,Laravel 5.6,当我在做我的laravel项目时,我犯了这个错误,即使经过这么多的改变和努力,我也无法解决它。我希望我能找到一些解决办法 我的错误: Symfony\Component\Debug\Exception\fatalthrowable错误与一起引发 消息“类”应用程序/帖子“未找到” CommentsController.php <?php namespace App\Http\Controllers; use \Auth; use App\Post; use Illuminate\Http
<?php
namespace App\Http\Controllers;
use \Auth;
use App\Post;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use App\Http\Requests;
use App\Comment;
use Session;
use DB;
class CommentsController extends Controller
{
public function store(Request $request)
{
$this->validate($request, [
'name' => 'required',
'email' => 'required',
'comment' => 'required'
]);
$post = Post::find('id');
$comments = new Comment();
$comments->name = $request->name;
$comments->email = $request->email;
$comments->comment = $request->comment;
$comments->approved = true;
$comments->post()->associate($post);
$comments->save();
Session::flash('success', 'Comment was added');
return redirect()->route('posts.show', [$post->id]);
//return redirect('/posts')->with('success', 'Comment Created
Successfully');
}
}`
`
My Web.php(路由文件)
`
`注意Post.php文件 使用App\Post
只是一个大写字母,不是所有的应用程序都在控制器顶部写下这段代码
use App\Post;
或
更改此代码
$post = Post::find('id');
到
我想这个问题已经解决了。Post.php文件在哪里?文件位于app/Post.php中,我的Post.php安装了名为Post.php的初始目录@JerodevSave file,只需使用
composer dump autoload
旁注:在你的url'/posts/{Post\u id}'
中有一个参数,但是您也忘了将其添加到控制器中:公共函数存储(Request$Request,$post\u id)
以及$post=post::find($post\u id)代码>没有这样的使用APP\Post代码>
use App\Post;
$post = Post::find('id');
$post = \App\Post::find('id');