简体   繁体   中英

Laravel 5.6 Class App\Http\Controllers\PostController does not exist

I have searched and found a similar question that was asked before but it did not solve my problem of composer update and composer dumpautoload did not solve it.

I am creating a CMS based website I have created with a PostsController and a create method.

I return a view and the route is below:

  Route::get('/post/create',[
'uses' => 'PostController@create',
'as' =>  'post.create'

]);]

this is PostsController@create

<?php

namespace App\Http\Controllers;
namespace App\Http\Controllers\PostController;
use Illuminate\Http\Request;
use Illuminate\Http\Controllers;


class PostsController extends Controller
 {
  /**
   * Display a listing of the resource.
   *
   * @return \Illuminate\Http\Response
   */
   public function index()
     {
       //
      }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
     public function create()
         {
           return view('admin.posts.create');
             }

浏览器错误截图

Please don't say this question has been asked before.

Help me! I have checked laracast but the link bellow did not work.

https://laracasts.com/discuss/channels/general-discussion/reflectionexception-class-apphttpcontrollersadminadmincontroller-does-not-exist

'uses' => 'PostController@create',

this is Post.

class PostsController extends Controller

this is Posts.

These are must same. Its just letter mistake.

You have used wrong route. Edit your route to

Route::get('/posts/create',[
'uses' => 'PostsController@create',
'as' =>  'posts.create'
]);]

There are lot of syntax errors. Follow names with caution.

  1. Remove second namespace line namespace App\\Http\\Controllers\\PostController;// remove this one
  2. Error in class name, should be use Illuminate\\Http\\Controller;// singular
  3. Route has to follow exact class name 'uses' => 'PostsController@create',//plural

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM