Search code examples
phplaravelclasstarget

Target class [ ] does not exist


I see this question a lot, and I tried many of the solutions but none seems to help. I hope that with my code shown I'll be able to work it out!

This is my route:

Route::view('/', 'pages.home');
Route::view('about', 'pages.about');
//Route::view('shop', 'shop.shop');
Route::get('shop', 'App\Http\Controllers\Shop\ShopController@displayShop');

and this is my controller:

<?php

namespace App\Http\Controllers\Shop;

use Illuminate\Http\Request;
use App\Models\Category;

class ShopController extends Controller
{
    public function displayShop() {
        $data['categories'] = Category::getCategories();
        return view('shop,shop', $data);
    }
}

And here is where my file is located [1]: https://i.sstatic.net/rM4as.png

thank you for your help!


Solution

  • If your are using Laravel 8, the new way to call controllers from route is

    Route::get('shop', [ShopController::class, 'displayShop']);