Happy Laracon Week! All accounts are 60% off this week.

finalhurdle27's avatar

My app is storing filenames in the database as /private/var/tmp/phpB5fgal etc..

Apologies if this has been discussed before but I can't find anything in the forums.

I have linked public/storage using php artisan storage:link and this is my method

public function store(StoreJobRequest $request) {

    $fields = $request->validated();
    if ($request->hasFile('file')) {
        $fields['job_spec'] = $request->file('job_spec')->store('files/job-specs');
        //$fields['job_spec'] = Storage::disk('public')->put('files/job-specs', $request->job_spec);
    }

    $request->user()->jobs()->create($fields);
    
    return redirect()->route('jobs.index')->with('status', 'Job created successfully');

}

But when i check the database its storing the job_spec column with the private/var/tmp/random_string. I also can't see the uploaded file in my public/storage directory. I have tried different ways of storing the file but still get the same the result.

My local .env has FILESYSTEM_DISK=public

Can anyone help me? It's probably a really stupid error.

0 likes
5 replies
tykus's avatar

Is the file input named file or job_spec?

finalhurdle27's avatar

I've just realised why thanks to your comment. It is now working as expected.

camillaroblesa's avatar

Glad you figured it out! That input name mismatch catches me off guard sometimes too. Matching the form field name exactly in $request->file() is so easy to miss.

Please or to participate in this conversation.