app/Http/Controllers/ShopController.php
/**
     * Update the specified resource in storage.
     *
     * @param Request $request
     * @param Shop $shop
     * @return JsonResponse
     */
Update the specified resource in storage.
@param Request $request
@param Shop $shop
@return JsonResponse
Update the specified resource in storage . @param Request $request @param Shop $shop @return JsonResponse
public function update(Request $request, Shop $shop)
    {
        $request->validate([
            'name' => 'max:255',
            'mobile' => "nullable|unique:Users,mobile",
            'image' => 'nullable|image|max:1999'
        ]);
        $user = User::query()->where('id', '=', $shop->user_id)->first();
        $user->mobile = $request->mobile ? $request->mobile : $user->mobile;
        $user->name = $request->name ? $request->name : $user->name;
        $user->role = $request->role ? $request->role : $user->role;
        if ($request->hasFile('image')) {
            $image = Helper::save_file($request->image, 'shop');
            $user->image = $image;
            File::delete($shop->image);
        }
        $shop->address = $request->address ? $request->address : $shop->address;
        $shop->status = $request->status ? $request->status : $shop->status;
        $shop->description = $request->description ? $request->description : $shop->description;
        if ($user->save() && $shop->save()) {
            $data = $shop->load('user');
            return Helper::success_response_with_data(new ShopResource($data));
        }
        return Helper::error_response();
    }
public function update ( Request $ request , Shop $ shop ) { $ request -> validate ( [ 'name' => 'max:255' , 'mobile' => " nullable|unique:Users,mobile " , 'image' => 'nullable|image|max:1999' ] ) ; $ user = User :: query ( ) -> where ( 'id' , '=' , $ shop -> user_id ) -> first ( ) ; $ user -> mobile = $ request -> mobile ? $ request -> mobile : $ user -> mobile ; $ user -> name = $ request -> name ? $ request -> name : $ user -> name ; $ user -> role = $ request -> role ? $ request -> role : $ user -> role ; if ( $ request -> hasFile ( 'image' ) ) { $ image = Helper :: save_file ( $ request -> image , 'shop' ) ; $ user -> image = $ image ; File :: delete ( $ shop -> image ) ; } $ shop -> address = $ request -> address ? $ request -> address : $ shop -> address ; $ shop -> status = $ request -> status ? $ request -> status : $ shop -> status ; $ shop -> description = $ request -> description ? $ request -> description : $ shop -> description ; if ( $ user -> save ( ) && $ shop -> save ( ) ) { $ data = $ shop -> load ( 'user' ) ; return Helper :: success_response_with_data ( new ShopResource ( $ data ) ) ; } return Helper :: error_response ( ) ; }
Update the specified resource in storage.
Update the specified resource in storage .