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
Change
to
You could simply include the class, add the following at the top of the web.php file
Include first your Controler in
web.php
useinguse AppHttpControllersHomeController;
then create route just like this
Route::get('/home', [HomeController::class, 'index'])->name('home');
full Code Try this one