0

I have created the web route correctly.

use App\Http\Controllers\FrontendCourseController;

Route::get('update-item', [FrontendCourseController::class, 'update'])->name('update-item');

and add a method update. Also, I have created controller correctly.

<?php

namespace App\Http\Controllers;

use App\Helpers\CurrencyHelper;
use Auth;
use DB;
use App\Models\Course\Course;
use App\Models\Item;

class FrontendCourseController extends Controller
{
   public function __construct()
   {
       $this->middleware('auth');
   }
  
   public function update()
   {
       dd('Page Update is working');

       return view('update-item');
   }
}

But I keep getting this error message

Method App\Http\Controllers\FrontendCourseController::update does not exist.

Despite clearing caches using

php artisan route:cache

enter image description here Where am I doing wrong?

Dominic
  • 341
  • 4
  • 15
  • try clearing cache ,php artisan route:clear but as per question you have cached route instead of cleearing using php artisan route:cache – John Lobo Jul 08 '21 at 14:01
  • @JohnLobo still get the same error – Dominic Jul 08 '21 at 14:10
  • @Dominc can you show full controller code – John Lobo Jul 08 '21 at 14:10
  • @JohnLobo check above; I have updated the code above – Dominic Jul 08 '21 at 14:14
  • every think looks good.make sure user is authenticated and once try clearing php artisan view:clear and php artisan route:clear .if still not working then run php artisan optimize – John Lobo Jul 08 '21 at 14:15
  • @JohnLobo I have run all, but still getting the same error – Dominic Jul 08 '21 at 14:20
  • @Dominic Why do you need `use App\Http\Controllers\FrontendCourseController;` in route file? – nice_dev Jul 08 '21 at 14:21
  • @nice_dev, any suggestion? – Dominic Jul 08 '21 at 14:22
  • @Dominic First is to remove that. Second is, try and run `composer dump-autoload` and check again. Also, I have personally followed `Controller@method_name` syntax. Is your current syntax something new in newer versions of Laravel? – nice_dev Jul 08 '21 at 14:23
  • Something like `Route::get('update-item', ['uses' => 'FrontendCourseController@update'])->name('update-item');` – nice_dev Jul 08 '21 at 14:25
  • @nice_dev Get this error `Target class [FrontendCourseController] does not exist.` – Dominic Jul 08 '21 at 14:28
  • @nice_dev The usage of the namespace is actually correct, see [docs](https://laravel.com/docs/8.x/routing#the-default-route-files). @Dominic Are you sure the `FrontendCourseController` is located in the `App\Http\Controllers` directory? – Eric Landheer Jul 08 '21 at 14:34
  • @nice_dev I have added an image of the controller above, kindly check. – Dominic Jul 08 '21 at 14:43
  • @Dominic What is ur Laravel version? – nice_dev Jul 08 '21 at 14:45
  • @nice_dev Laravel Framework 8.26.1 – Dominic Jul 08 '21 at 14:47
  • @EricLandheer Not saying it's wrong but it shouldn't be needed considering everything in App namespace is autoloaded by composer. – nice_dev Jul 08 '21 at 14:53
  • @Dominic I would love to reproduce but Laravel docs says me to install a lot of pre-requisite softwares to install Laravel 8.x – nice_dev Jul 08 '21 at 14:55
  • @Dominic Does this help? https://stackoverflow.com/questions/63807930/target-class-controller-does-not-exist-laravel-8 – nice_dev Jul 08 '21 at 14:59
  • @Dominic I have recreated the provided code locally into an existing project (Laravel 8.48), it is working correctly here. You could try running: `composer dump-autoload`. If that does not work, could you please check if the `FrontendCourseController` is actually in the `App\Http\Controllers` directory? Could you perhaps provide a screenshot of the directory? If the file is in the wrong directory, please move it to the correct directory and run `composer dump-autoload`. – Eric Landheer Jul 08 '21 at 15:25
  • @EricLandheer check screenshot above – Dominic Jul 08 '21 at 15:26
  • @Dominic Sorry missed that, did you run `composer dump-autoload`? – Eric Landheer Jul 08 '21 at 15:27
  • @EricLandheer yes – Dominic Jul 08 '21 at 15:28
  • @Dominic It seems to be a stubborn caching issue! If none of these commands threw a error, and you have tried `php artisan view:clear` `php artisan route:clear` `php artisan cache:clear` `php artisan config:clear` `composer dump-autoload` I am out of ideas, perhaps someone else has another suggestion. It is working fine on my machine. Final thing: You could try and restart your local server? What server are you running, are you running anything like `OPcache` by any chance? – Eric Landheer Jul 08 '21 at 15:35
  • 1
    Thanks, @nice_dev, and everyone who contributed. I found where the issue was. The App folder was duplicated, I removed one, and it works. – Dominic Jul 08 '21 at 15:42

0 Answers0