Cataract0523's avatar

L5.2 [ReflectionException] Class 'ClassName' does not exist

Guys I’m getting the following error when I try to run `php artisan route:li Theoretically there is no mistakes on the naming convention.

[ReflectionException] Class 'ClassName' does not exist

I created a controller from the CLI and I am pretty sure it exists

Here's what I tried so far:

  1. composer dump-autoload
  2. composer install
  3. php artisan config:cache
  4. php artisan config:clear

Here's my autoload from composer:

"autoload": {
        "classmap": [
            "database",
            "app/Http/Controllers",
            "app/Models",
            "app/Console/Commands"
        ],
        "psr-0": {
            "scdda": "app/"
        },
        "psr-4": {
            "App\": "app/"
        }
    }

Here is the route:

Route::resource('newroute','MyNewController',['only'=>['index','delete']]);

and here's my newly created controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

class MyNewController 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()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
0 likes
4 replies
tisuchi's avatar
tisuchi
Best Answer
Level 70

@cac

The psr-4 link suppose to be like this-

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

So, your full code is like this-

"autoload": {
        "classmap": [
            "database",
            "app/Http/Controllers",
            "app/Models",
            "app/Console/Commands"
        ],
        "psr-0": {
            "scdda": "app/"
        },
        "psr-4": {
            "App\\": "app/"
        }
    }

It should work now.

In some cases, composer dump-autoload may be required. If you are facing same issue still, run

composer dump-autoload
5 likes
Cataract0523's avatar

@TISUCHI - Man I must be blind because I didnt see what you did there. It all look the same to me...

1 like
tisuchi's avatar

@CAC - Actually, you are right. It supposes to be \\ but it shows single only. I already update my code. Make sure that you have the same code now.

2 likes

Please or to participate in this conversation.