Home > Software design >  Target class [App\Http\Controllers\User] does not exist
Target class [App\Http\Controllers\User] does not exist

Time:10-30

I'm creating a page which can edit the filename, artist name and album name of the uploaded song. Currently the error states as

Target class [App\Http\Controllers\User] does not exist

web.php

use App\Http\Controllers\UploadController;
Route::post('/updatesongs/{id}', [UploadController::class,'update']);

UploadController.php

public function update(Request $request,User $id)
    {   
        $songname = $request->input('song_title');
        $songartist = $request->input('song_artist');
        $songalbum = $request->input('song_album');
        DB::update('update music_uploads set filename = ?, artistname = ?, albumname = ? where id =?', [$songname, $songartist, $songalbum,$id]);
        echo "Updated successfully <br>";
        echo '<a href="/ngsongs">Click here to return</a>';
    }

Solutions I've tried

  1. RouteServiceProvider.php
     protected $namespace = 'App\\Http\\Controllers';

uncommenting this line doesn't solve the problem

  1. clean the cache php artisan route:cache doesn't work

Any other solutions or is my code wrong?

CodePudding user response:

you should provide the namespace for the User model that you use as a parameter in your controller:

use App\Models\User

// .......

public function update(Request $request,User $id)
  • Related