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
RouteServiceProvider.php
protected $namespace = 'App\\Http\\Controllers';
uncommenting this line doesn't solve the problem
- 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)