0

Hi so i'm making simple crud API but somehow when i check the route i keep showing Target class [DataController] does not exist

and this is my controller

namespace App\Http\Controllers\DataController;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

use App\Data;

class DataController extends Controller
{
    public function index()
    {
        return Data::all();
    }
}

and this my route:

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});

Route::get('data','DataController@index');
Route::post('data','DataController@create');
Route::put('/data/{id}','DataController@update');
Route::delete('/data/{id}','DataController@delete');

I'm pretty new learn about API in Laravel and i saw use php artisan config:cache and composer auto-load don't work as well so maybe something wrong in my code or what?

lagbox
  • 48,571
  • 8
  • 72
  • 83
  • this is a change in Laravel 8 and how it handles your routes to controllers. It no longer prefixes any namespace to the controller to resolve it .... i marked this as a duplicate as all questions like this are the same issue – lagbox Sep 12 '20 at 08:40
  • remove DataController from the namespace. namespace should only contain the path to file, not the file name – Faramarz Qoshchi Sep 12 '20 at 08:40
  • yes that too as Faramarz has stated (most likely) though you could have that in that namespace if you like – lagbox Sep 12 '20 at 08:41
  • 1
    i read the documentation and it's different how to route in laravel 8 thx for your answer m8 – Vincent Junior Sep 12 '20 at 08:52
  • no problem, good luck and have fun with Laravel – lagbox Sep 12 '20 at 09:01

0 Answers0