Ap3twe
4 months ago

Updating Database using updateOrCreate method

Posted 4 months ago by Ap3twe

Hey, am inserting images to a database. I tried updateOrCreate but It replaces every record in the database with the new data. I do not want to update just insert data to tables I assigned null. I tried two methods. one work perfectly I get the file temp-name in the database, but for me to get the file name, I triedupdateOrCreate, and create method but it deletes all records in the schema.

This deletes all my records

 $project = Project::updateOrCreate(array_merge(request([  'labphotofiles', 'labstlfiles', 'user_id',
      
         ]),
        //  bottom I have used array_merge to store the user id
         [
         'user_id'=>auth()->id(),
         'labphotofiles' => $labphotofileNameToStore,
         'labstlfiles' => $labstlfileNameToStore,
          ]));

Another method I used is save method. This one works, adds the data but how can I attach the filename to it?

$project->labphotofiles = request('labphotofiles');
$project->labstlfiles = request('labstlfiles');
 $project->save();

Please sign in or create an account to participate in this conversation.