Prathamesh6921's avatar

Unable to store files in the databse

Not getting any error while uploading the file in the database

I am trying to store multiple files in the database in laravel but not getting any error, I also check with the dd in the backend but got nothing. I don't know how check. Can anyone help me how how to fix this?

The path in which I'm storing the diploma files is used to store another files so I am using same folder(storage/app/license) and I have created a folder under app (diploma) but it is also not working

$diplomaname = $request->get('diplomaname');
$diplomayear = $request->get('diplomayear');
$all_params = $request->keys();
$total_diplomas = preg_grep('/^diplomafile_.*/', $all_params);

if ($diplomaname != null && $diplomayear != null) {
  $dip = new Diplomas();
  $dip->lawyer_id = $lawyer-> id;
  $dip->diploma_institution = $diplomaname;
  $dip->year = $diplomayear;
  $dip->save();
}
for ($j = 0; $j < count($total_diplomas); $j++) {
  if ($request->get('diplomafile_'.$j) != null) {
    $filename = $request-> file('diplomafile_'.$j)->store('licenses');
    $dipfile = new Diplomafile();
    $dipfile->lawyer_id = $lawyer->id;
    $dipfile->file = $filename;
    $dipfile->save();
  }
}

ia hve created separate table to store files as they are multiple ,please help with this i am on this since last 2 days, i am not even getting any error,earlier i was gettting error 'call to member function store null' but as made changes in my frontend jquery & ajax code so that error is not coming and also done severals dd() but got nothing

0 likes
1 reply
D9705996's avatar
D9705996
Best Answer
Level 51

Are you receiving any files in the request? At the top of your controller method add dd($request->allFiles());

If this is empty your issue is with the way you are uploading the files from the front end. If you can see the files in the request then you have a issue with the backend code. At least helps you narrow down where to get started.

There is good field upload tutorial

https://laraveldaily.com/laravel-upload-file-and-hide-real-url-for-secure-download-under-uuid/

1 like

Please or to participate in this conversation.