7 months ago

How to return update result as json object

Posted 7 months ago by MattB

I have the following which is just an update to a db that takes in a Json object from vue. I cannot figure out how to return the result as a json object back to vue. What have I done wrong? As it stands, I get no response showing when I check in the developer tools of Chrome:

public function update(Request $request, $id)
        $imageSearch = Gallery::findOrFail($id);
        $file_image = $request->file('imageFile');
        $file_thumbnail = $request->file('thumbnailFile');
        $input = $request->all();
        if($file_image && $file_thumbnail){
            $fileName = $file_image->getClientOriginalName();
            $thumbName = $file_thumbnail->getClientOriginalName();
            $path_images = 'images';
            $path_thumbnail = 'thumbnails';
            if($file_image->move($path_images, $fileName) && $file_thumbnail->move($path_thumbnail, $thumbName)){
                $input['image'] = '/' . $fileName;
                $input['thumbnail'] = '/' . $thumbName;
                $input['name'] = $request->name;
                $input['species_id'] = $request->species;
                $input['tag'] = $request->tag;
                $input['patreon'] = $request->patreon;
                $update = $imageSearch->update($input);
                return response()->json([
                    'update' => $update,
                    'message' => 'Image has been Updated'


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