Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

anon160124's avatar

API public function store

When I uploaded the app to the server, the code for adding images to the gallery stopped working. On localhost, the code worked without error and the images were added to the DB and folder.

The development environment is windows. Server linux. Images are sent via axios to the api controller. no error message will be added to the console. Images will not be written to the database or folder. Thanks for help

public function store(Request $request) {

    $this->validate($request, [
        'images' => 'required',
        'images.*' => 'image|mimes:jpeg,png,jpg,gif,svg|max:3600'
    ]);

    $albumId = $request->get('album_id');

    if($request->hasFile('images')) {
        foreach($request->file('images') as $image) {
            $filename = strtolower ( trim ( $image->getClientOriginalName() ));
            $name = time().rand(100,999).$filename;
            $destinationPath = public_path('img/gallery-img/');
            $image->move($destinationPath, $name);

            $image = new Image([
                'image' => $name,
                'album_id' => $albumId
            ]);

            $image->save();
        }
    }

    return response()->json([
    'message' => 'All images uplaoded successfully',
    ], 201);
}

The full app code is here: https://github.com/Martin-1182/CMS

server: Apache 2,4 PHP 7.3

0 likes
2 replies
Amaury's avatar

@martin1182 Dis you create create the symbolic link from public/storage to storage/app/public:

php artisan storage:link

Please or to participate in this conversation.