php - Laravel download code stopped after a weekend
one text
So i am coding a application for users, a user is able to download 'files'. if a user clicks on the 'download' button it should run this code:
public function download(Request $request, int $fileId)
{
$id = Auth::user();
$userId = $id->id;
$fullfile = File::find($fileId);
$downloadfile = File::find($fullfile, ['file'])->pluck('file')->last();
$checkPivot = DB::table('download')->where('file_id', '=', $fileId)->where('user_id', '=', $userId)->first();
dd($checkPivot);
if ($checkPivot == NULL) {
$fullfile->userfile()->attach($id);
return response()->download($downloadfile);
return back();
} else {
return response()->download($downloadfile);
return back();
}
}
the code first checks for the user his role: (admin, partner, dealer) after that we are getting the user id itself. this is needed for the pivot table query under the If statement. then i will get the full row of the database table called 'file' in the row file. is a column called 'file' (like .docx, .pdf, .xlsx etc..), so we retrieve that. then i fire a query to check if the user already downloaded the file (by checking the pivot table) if not, then run the IF statement, otherwise run the ELSE statement.
even if i put the whole if else in psuedo code, it just keeps on downloading the file. but not placing a new row if needed in the pivot table.
before the weekend it worked 100% flawless. but now i just started up my pc and it stopped working for most part.
any tips on where to start? or what to look for, i never debug so i am really new to solving a bug like this
Source