• <bdo id='0ZAtw'></bdo><ul id='0ZAtw'></ul>

  • <small id='0ZAtw'></small><noframes id='0ZAtw'>

    <legend id='0ZAtw'><style id='0ZAtw'><dir id='0ZAtw'><q id='0ZAtw'></q></dir></style></legend>

    1. <i id='0ZAtw'><tr id='0ZAtw'><dt id='0ZAtw'><q id='0ZAtw'><span id='0ZAtw'><b id='0ZAtw'><form id='0ZAtw'><ins id='0ZAtw'></ins><ul id='0ZAtw'></ul><sub id='0ZAtw'></sub></form><legend id='0ZAtw'></legend><bdo id='0ZAtw'><pre id='0ZAtw'><center id='0ZAtw'></center></pre></bdo></b><th id='0ZAtw'></th></span></q></dt></tr></i><div id='0ZAtw'><tfoot id='0ZAtw'></tfoot><dl id='0ZAtw'><fieldset id='0ZAtw'></fieldset></dl></div>
        <tfoot id='0ZAtw'></tfoot>
      1. 类 AppHttpControllersPostController 不存在

        时间:2023-10-11

      2. <tfoot id='EFjxE'></tfoot>
        <legend id='EFjxE'><style id='EFjxE'><dir id='EFjxE'><q id='EFjxE'></q></dir></style></legend>
      3. <small id='EFjxE'></small><noframes id='EFjxE'>

      4. <i id='EFjxE'><tr id='EFjxE'><dt id='EFjxE'><q id='EFjxE'><span id='EFjxE'><b id='EFjxE'><form id='EFjxE'><ins id='EFjxE'></ins><ul id='EFjxE'></ul><sub id='EFjxE'></sub></form><legend id='EFjxE'></legend><bdo id='EFjxE'><pre id='EFjxE'><center id='EFjxE'></center></pre></bdo></b><th id='EFjxE'></th></span></q></dt></tr></i><div id='EFjxE'><tfoot id='EFjxE'></tfoot><dl id='EFjxE'><fieldset id='EFjxE'></fieldset></dl></div>

                • <bdo id='EFjxE'></bdo><ul id='EFjxE'></ul>
                    <tbody id='EFjxE'></tbody>
                  本文介绍了类 AppHttpControllersPostController 不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  让我先说我知道这个问题经常被问到."当我说没有任何效果时,请相信我.

                  Let me just start by saying "I know this question gets asked a lot." believe me when i say nothing has worked for me.

                  我创建了一个名为 PostController 的控制器.这是我博客的控制器.当我导航到我的博客时,我收到以下错误 Class AppHttpControllersPostController does not exist 即使它确实存在.控制器名为 PostController.php.下面是路由的样子 Route::get('blog','PostController@index');.我读到运行一些 composer 命令会有所帮助,但没有一个对我有帮助.composer dumpautoload 以及 composer update.我在这里错过了一些步骤吗?有人遇到过类似的问题吗?如果需要其他信息,请告诉我.

                  I have created a controller called PostController. This is a controller for my blog. When I navigate to my blog i get the following error Class AppHttpControllersPostController does not exist even though it does exist. The controller is called PostController.php. Here is what the route looks like Route::get('blog','PostController@index');. I have read that running some composer commands will help but none of them have helped me. composer dumpautoload as well as composer update. Am i missing some step here? Anyone run into a similar problem? Please let me know if additional information is needed.

                  编辑这是顶部的命名空间.

                  use AppHttpControllers;
                  use AppPosts;
                  use AppUser;
                  use AppHttpControllersController;
                  use AppHttpRequestsPostFormRequest;
                  use IlluminateHttpRequest;
                  

                  这是整个控制器.

                  <?php 
                  use AppHttpControllers;
                  use AppPosts;
                  use AppUser;
                  use AppHttpControllersController;
                  use AppHttpRequestsPostFormRequest;
                  use IlluminateHttpRequest;
                  
                  
                  
                  class PostController extends Controller {
                  
                  /**
                   * Display a listing of the resource.
                   *
                   * @return Response
                   */
                      public function index()
                      {
                        //fetch 5 posts from database which are active and latest
                        $posts = Posts::where('active',1)->orderBy('created_at','desc')->paginate(5);
                        //page heading
                        $title = 'Latest Posts';
                        //return home.blade.php template from resources/views folder
                        return view('blog/home')->withPosts($posts)->withTitle($title);
                      }
                  
                  
                  /**
                   * Show the form for creating a new resource.
                   *
                   * @return Response
                   */
                      public function create(Request $request)
                      {
                        // if user can post i.e. user is admin or author
                        if($request->user()->can_post())
                        {
                          return view('blog.create');
                        }    
                        else 
                        {
                          return redirect('blog');
                        }
                      }
                  
                  
                  /**
                   * Store a newly created resource in storage.
                   *
                   * @return Response
                   */
                      public function store(PostFormRequest $request)
                      {
                        $post = new Posts();
                        $post->title = $request->get('title');
                        $post->body = $request->get('body');
                        $post->slug = str_slug($post->title);
                        $post->author_id = $request->user()->id;
                        if($request->has('save'))
                        {
                          $post->active = 0;
                          $message = 'Post saved successfully';            
                        }            
                        else 
                        {
                          $post->active = 1;
                          $message = 'Post published successfully';
                        }
                        $post->save();
                        return redirect('edit/'.$post->slug)->withMessage($message);
                      }
                  
                  
                  /**
                   * Display the specified resource.
                   *
                   * @param  int  $id
                   * @return Response
                   */
                      public function show($slug)
                      {
                        $post = Posts::where('slug',$slug)->first();
                        if(!$post)
                        {
                           return redirect('/')->withErrors('requested page not found');
                        }
                        $comments = $post->comments;
                        return view('posts.show')->withPost($post)->withComments($comments);
                      }
                  
                  
                  /**
                   * Show the form for editing the specified resource.
                   *
                   * @param  int  $id
                   * @return Response
                   */
                      public function edit(Request $request,$slug)
                      {
                        $post = Posts::where('slug',$slug)->first();
                        if($post && ($request->user()->id == $post->author_id || $request->user()->is_admin())){
                            return view('posts.edit')->with('post',$post);
                        }
                        return redirect('blog')->withErrors('you have not sufficient permissions');
                      }
                  
                  
                  /**
                   * Update the specified resource in storage.
                   *
                   * @param  int  $id
                   * @return Response
                   */
                      public function update(Request $request)
                      {
                        //
                        $post_id = $request->input('post_id');
                        $post = Posts::find($post_id);
                        if($post && ($post->author_id == $request->user()->id || $request->user()->is_admin()))
                        {
                          $title = $request->input('title');
                          $slug = str_slug($title);
                          $duplicate = Posts::where('slug',$slug)->first();
                          if($duplicate)
                          {
                            if($duplicate->id != $post_id)
                            {
                              return redirect('edit/'.$post->slug)->withErrors('Title already exists.')->withInput();
                            }
                            else 
                            {
                              $post->slug = $slug;
                            }
                          }
                          $post->title = $title;
                          $post->body = $request->input('body');
                          if($request->has('save'))
                          {
                            $post->active = 0;
                            $message = 'Post saved successfully';
                            $landing = 'edit/'.$post->slug;
                          }            
                          else {
                            $post->active = 1;
                            $message = 'Post updated successfully';
                            $landing = $post->slug;
                          }
                          $post->save();
                               return redirect($landing)->withMessage($message);
                        }
                        else
                        {
                          return redirect('blog')->withErrors('you have not sufficient permissions');
                        }
                      }
                  
                  
                  /**
                   * Remove the specified resource from storage.
                   *
                   * @param  int  $id
                   * @return Response
                   */
                      public function destroy(Request $request, $id)
                      {
                        //
                        $post = Posts::find($id);
                        if($post && ($post->author_id == $request->user()->id || $request->user()->is_admin()))
                        {
                          $post->delete();
                          $data['message'] = 'Post deleted Successfully';
                        }
                        else 
                        {
                          $data['errors'] = 'Invalid Operation. You have not sufficient permissions';
                        }
                        return redirect('blog')->with($data);
                      }
                  
                  
                  }
                  

                  谢谢.

                  推荐答案

                  如果 composer dumpautoload 没有帮助,请检查 PostController 中是否有正确的 namespace 声明.php 并仔细检查类名/路由声明中的拼写错误.

                  If composer dumpautoload is not helping then check if you have proper namespace declaration in PostController.php and double check for typos in class name/route declaration.

                  如果失败,请检查 composer.json 的自动加载配置,它应该是这样的:

                  If this fails check composer.json for autoload configuration, it should have something like this:

                  "autoload": {
                      "psr-4": {
                          "App\": "app/"
                      }
                  },
                  

                  作为旁注,您可以使用以下内容:

                  As a side note you could use something like this:

                  Route::get('blog',PostController::class . '@index');
                  

                  Route::get('blog',AppHttpControllersPostController::class . '@index');
                  

                  有了这个,任何体面的 IDE 都应该在找不到文件/有拼写错误时发出某种警告

                  With this any decent IDE should give some kind of a warning if it can't find the file/there's a typo

                  编辑:

                  你的文件应该有这样一行

                  Your file should have a line like this

                  namespace AppHttpControllers;
                  

                  在文件的开头,在 <?php<?php declare(strict_types = 1); 之后,如果您使用的是 php7 严格模式

                  At the beggining of the file, right after <?php or <?php declare(strict_types = 1); if you're using php7 strict mode

                  这篇关于类 AppHttpControllersPostController 不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何覆盖 Magento 控制器? 下一篇:在 CodeIgniter 中找不到错误类控制器

                  相关文章

                    <bdo id='qhGsH'></bdo><ul id='qhGsH'></ul>

                  <tfoot id='qhGsH'></tfoot>
                  <i id='qhGsH'><tr id='qhGsH'><dt id='qhGsH'><q id='qhGsH'><span id='qhGsH'><b id='qhGsH'><form id='qhGsH'><ins id='qhGsH'></ins><ul id='qhGsH'></ul><sub id='qhGsH'></sub></form><legend id='qhGsH'></legend><bdo id='qhGsH'><pre id='qhGsH'><center id='qhGsH'></center></pre></bdo></b><th id='qhGsH'></th></span></q></dt></tr></i><div id='qhGsH'><tfoot id='qhGsH'></tfoot><dl id='qhGsH'><fieldset id='qhGsH'></fieldset></dl></div>

                  1. <small id='qhGsH'></small><noframes id='qhGsH'>

                    1. <legend id='qhGsH'><style id='qhGsH'><dir id='qhGsH'><q id='qhGsH'></q></dir></style></legend>