SvH-Shane's avatar

Strange path created when updating or uploading a image file

Hi all!

I'm trying to update an image, but a problem arises that gives me a headache. I can't see it anymore.

The path that is now being created:

/private/var/folders/7g/wjqq87vd0wv22q9r4hwzzpzc0000gn/T/phpBOuYSD

What is supposed to be:

/storage/database/qsL5cakvq9hj4HM3Xja1gdOhCVeyiYWMAJjVTf2L.jpeg

I'm using the same method in this project but with other purposes and it works fine... So what am I missing?

public function update($postsAircraft, $slug)
    {
        $data = request()->validate([
            'title' => '',
            'progress_status' => '',
            'tail_id' => '',
            'location' => '',
            'screening_status' => '9',
            'image' => ['required', 'sometimes', 'file', 'image', 'max:2500'],
        ]);

        if (request('image')) {
			$imagePath = request('image')->store('database', 'public');

			$image = Image::make(public_path("/storage/{$imagePath}"));
			$image->text('test', 40, 40, function($font) {
			    $font->file('fonts/RobotoSlab-Bold.ttf');
			    $font->size(120);
			    $font->color('#fdf6e3');
			});
			$image->save();

			$imageArray = ['image' => $imagePath];
		}

        $postsAircraft->update($data);

        return redirect()->back()->with('message', 'Successfully updated the image.');
    }

Big thanks!

0 likes
2 replies
ollie_123's avatar

Hi @svh-shane you may be better using storeAs. i.e.

$image = $request->file('image');
$image->storeAs('public/database');

Also have you run the php artisan storage:link command?

Snapey's avatar

You are storing validated data which includes the temporary path to the image - not where you stored it.

You get imagePath here

$imagePath = request('image')->store('database', 'public');

but you never write it to the database

Please or to participate in this conversation.