tekitaamtk's avatar

Updating uploaded files

Hi Guys,

I am trying to solve an issue that I am facing with updating file's path in my database. The file was uploaded to the right directory but I was unable to store that path in my database. Can anyone help with it, provided below is my scripts.

public function update($id, UpdateinfrastructureRequest $request)
{
    $infrastructure = $this->infrastructureRepository->find($id);

    if (empty($infrastructure)) {
        Flash::error('Infrastructure not found');

        return redirect(route('infrastructures.index')); 
    }

    $path = Storage::putFile('storage', $request->file('inf_file'));

    $request['inf_file'] = $path;

    $infrastructure = $this->infrastructureRepository->update($request->all(), $id);

    Flash::success('Infrastructure updated successfully.');

    Thanks.
0 likes
3 replies
jlrdw's avatar

You said update. So how did you originally upload the file successfully.

If just updating, you unlink old and just update with new, like you did when originally creating (adding) it.

tekitaamtk's avatar

Hi,

Thanks for your comment. yes, the file uploaded successfully but the path that stored in the database is not the directory where the file is stored. In the database, this is what I get.

C:\xampp\tmp\phpA409.tmp

tekitaamtk's avatar

Thanks for the hint, problem solved.

    $infrastructure = $this->infrastructureRepository->find($id);

    $input = $request->all();

    if (empty($infrastructure)) {
        Flash::error('Infrastructure not found');

        return redirect(route('infrastructures.index')); 
    }

    $path = Storage::putFile('storage', $request->file('inf_file'));

    $input['inf_file'] = $path;

    $infrastructure = $this->infrastructureRepository->update($input, $id);

    Flash::success('Infrastructure updated successfully.');

Please or to participate in this conversation.