5 months ago

API public function store

Posted 5 months ago by Martin1182

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


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

The full app code is here:

server: Apache 2,4 PHP 7.3

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