RomainB
202
10
Laravel

ReflectionException (-1) Class Post does not exist

Posted 1 week ago by RomainB

Hi. Got a headache...

I've just created all admin pages for "category" resource of a blog website. Everything is okay.

I tried to do exactly the same structure to manage "post" resource. [email protected], create and store is okay.

But now i'm trying to do the edit and i got a: ReflectionException (-1) Class Post does not exist The error occurs even on destroy function call.

I past few hours trying to search over the web (event in this forum), tried artisan config:cache, composer dumpautoload -o (also without -o ), verified my Post class doesn't have any syntax error, check composer.json autoload. Nothing worked! My composer.json:

    "autoload": {
        "psr-4": {
            "App\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },

My Post class:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    protected $guarded = [];
    
    public function comments()
    {
        return $this->hasMany('Comment');
    }
    
    public function author()
    {
        return $this->belongsTo('User');
    }
    
    public function category()
    {
        return $this->belongsTo('Category');
    }
}

My PostController:

<?php

namespace App\Http\Controllers\AdminZone;

use App\Post;
use App\Category;
use Auth;
use App\Http\Controllers\Controller;
use App\Http\Requests\PostStoreUpdateRequest;

class PostController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }
    
    /**
     * Show the form for editing the specified resource.
     *
     * @param  Post  $post
     * @return \Illuminate\Http\Response
     */
    public function edit(Post $post)
    {
        $categories = Category::pluck('name', 'id');
        return view('admin.post.edit')->with('post', $post)->with('categories', $categories);
    }
// And some other code for other actions

My route:list for post:

GET|HEAD  | admin/post                     | admin::post.index       | App\Http\Controllers\AdminZone\[email protected]           | web,auth                                             |
|        | POST      | admin/post                     | admin::post.store       | App\Http\Controllers\AdminZone\[email protected]           | web,auth                                             |
|        | GET|HEAD  | admin/post/create              | admin::post.create      | App\Http\Controllers\AdminZone\[email protected]          | web,auth                                             |
|        | GET|HEAD  | admin/post/{post}              | admin::post.show        | App\Http\Controllers\AdminZone\[email protected]            | web,auth                                             |
|        | PUT|PATCH | admin/post/{post}              | admin::post.update      | App\Http\Controllers\AdminZone\[email protected]          | web,auth                                             |
|        | DELETE    | admin/post/{post}              | admin::post.destroy     | App\Http\Controllers\AdminZone\[email protected]         | web,auth                                             |
|        | GET|HEAD  | admin/post/{post}/edit         | admin::post.edit        | App\Http\Controllers\AdminZone\[email protected]            | web,auth                                             |

Does someone see anything wrong??

Please sign in or create an account to participate in this conversation.