skip to Main Content

I have a new Laravel project running Valet + (laravel 8.12).

Controller:

app->Http->Controllers->PageController.php

<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;

class PageController extends Controller
{
    public function dashboard()
    {
        return view('show');
    }
}

Web.php

Route::get('/', function () {
    return view('home');
});

Route::get(
    '/dashboard',
    [PageController::class, 'show']
)->name('dashboard');

Auth::routes();
Route::get('/home', [AppHttpControllersHomeController::class, 'index'])->name('home');

Auth::routes();
Route::get('/home', [AppHttpControllersHomeController::class, 'index'])->name('home');

I have a link on my homepage
href="dashboard"
however when this link is clicked I get an error:

lluminateContractsContainerBindingResolutionException
Target class [PageController] does not exist.
http://myportal.test/dashboard

I have tried running:
composer dump-autoload
php artisan route:cache
php artisan optimize
php artisan clear-compiled

I dont fully understand why when I added
php artisan ui vue –auth
why the routing had
[AppHttpControllersHomeController::class
added for the route?

I have usually used:
route::get(‘/dashboard’, ‘PageController@show’);
which usually works.

None of these have worked to solve the issue. I have another Laravel project running in the same Valet+ environment that is working fine (although using a different version of Laravel).

I haven’t been able to find a solution to my problem online that has helped me solve this problem. Can anyone point me in the right direction please?

3

Answers


  1. Change

    Route::get(
        '/dashboard',
        [PageController::class, 'show']
    )->name('dashboard');
    

    to

    Route::get(
        '/dashboard',
        [AppHttpControllersPageController::class, 'show']
    )->name('dashboard');
    
    Login or Signup to reply.
  2. You could simply include the class, add the following at the top of the web.php file

    use AppHttpControllersPageController;
    
    Login or Signup to reply.
  3. Include first your Controler in web.php useing
    use AppHttpControllersHomeController;
    then create route just like this

    Route::get('/home', [HomeController::class, 'index'])->name('home');

    full Code Try this one

    use AppHttpControllersHomeController;
    
    Route::get('/home', [HomeController::class, 'index'])->name('home');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search