app/Http/Controllers/CustomerController.php
/**
     * Update the specified resource in storage.
     *
     * @param Request $request
     * @param Customer $Customer
     * @return JsonResponse
     */
Update the specified resource in storage.
@param Request $request
@param Customer $Customer
@return JsonResponse
Update the specified resource in storage . @param Request $request @param Customer $Customer @return JsonResponse
public function update(Request $request, Customer $Customer)
    {
        $request->validate([
            'name' => 'required|max:255',
            'image' => 'nullable|image|max:1999'
        ]);
        $user_id = $Customer->user_id;
        $user = User::query()->find($user_id);
        $user->mobile = $request->mobile ? $request->mobile : $user->mobile;
        $user->name = $request->name ? $request->name : $user->name;
        $user->country = $request->country ? $request->country : $user->country;
        $user->role = $request->role ? $request->role : $user->role;
        if ($request->hasFile('image')) {
            $image = Helper::save_file($request->image, 'user');
            $user->image = $image;
            File::delete($user->image);
        }
        $Customer->address = $request->address ? $request->address : $Customer->address;
        $Customer->isActive = $request->isActive ? $request->isActive : $Customer->isActive;
        if ($user->save() && $Customer->save()) {
            return Helper::response_with_data(Customer::with('user')->find($Customer->id), false);
        }
        return Helper::response_with_data(null, true);
    }
public function update ( Request $ request , Customer $ Customer ) { $ request -> validate ( [ 'name' => 'required|max:255' , 'image' => 'nullable|image|max:1999' ] ) ; $ user_id = $ Customer -> user_id ; $ user = User :: query ( ) -> find ( $ user_id ) ; $ user -> mobile = $ request -> mobile ? $ request -> mobile : $ user -> mobile ; $ user -> name = $ request -> name ? $ request -> name : $ user -> name ; $ user -> country = $ request -> country ? $ request -> country : $ user -> country ; $ user -> role = $ request -> role ? $ request -> role : $ user -> role ; if ( $ request -> hasFile ( 'image' ) ) { $ image = Helper :: save_file ( $ request -> image , 'user' ) ; $ user -> image = $ image ; File :: delete ( $ user -> image ) ; } $ Customer -> address = $ request -> address ? $ request -> address : $ Customer -> address ; $ Customer -> isActive = $ request -> isActive ? $ request -> isActive : $ Customer -> isActive ; if ( $ user -> save ( ) && $ Customer -> save ( ) ) { return Helper :: response_with_data ( Customer :: with ( 'user' ) -> find ( $ Customer -> id ) , false ) ; } return Helper :: response_with_data ( null , true ) ; }
Update the specified resource in storage.
Update the specified resource in storage .