Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 类别';App/Post&x27;未在laravel-5.6中找到_Php_Laravel_Laravel 5.6 - Fatal编程技术网

Php 类别';App/Post&x27;未在laravel-5.6中找到

Php 类别';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

当我在做我的laravel项目时,我犯了这个错误,即使经过这么多的改变和努力,我也无法解决它。我希望我能找到一些解决办法

我的错误:

Symfony\Component\Debug\Exception\fatalthrowable错误与一起引发 消息“类”应用程序/帖子“未找到”

CommentsController.php

<?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');