app/Http/Controllers/BrandController.php
/**
     * Update the specified resource in storage.
     *
     * @param Request $request
     * @param Brand $brand
     * @return JsonResponse
     */
Update the specified resource in storage.
@param Request $request
@param Brand $brand
@return JsonResponse
Update the specified resource in storage . @param Request $request @param Brand $brand @return JsonResponse
public function update(Request $request, Brand $brand)
    {
        $request->validate(
            [
                'name' => 'nullable',
                'shop_id' => 'nullable|exists:shops,id'
            ]
        );
        $data['name'] = $request->name ? $request->name : $brand->name;
        $data['shop_id'] = $request->shop_id ? $request->shop_id : $brand->shop_id;
        $data['details'] = $request->details ? $request->details : $brand->details;
        $data['origin'] = $request->origin ? $request->origin : $brand->origin;
        $data['isActive'] = !empty($request->isActive) ? $request->isActive : $brand->isActive;
        if ($request->hasFile('image')) {
            $image = Helper::save_file($request->image, 'brand');
            $data['image']  = $image;
            File::delete($brand->image);
        }
        if ($brand->update($data)){
            return Helper::response_with_data(Brand::query()->find($brand->id), false);
        }
        return Helper::response_with_data(null, true);
    }
public function update ( Request $ request , Brand $ brand ) { $ request -> validate ( [ 'name' => 'nullable' , 'shop_id' => 'nullable|exists:shops,id' ] ) ; $ data [ 'name' ] = $ request -> name ? $ request -> name : $ brand -> name ; $ data [ 'shop_id' ] = $ request -> shop_id ? $ request -> shop_id : $ brand -> shop_id ; $ data [ 'details' ] = $ request -> details ? $ request -> details : $ brand -> details ; $ data [ 'origin' ] = $ request -> origin ? $ request -> origin : $ brand -> origin ; $ data [ 'isActive' ] = ! empty ( $ request -> isActive ) ? $ request -> isActive : $ brand -> isActive ; if ( $ request -> hasFile ( 'image' ) ) { $ image = Helper :: save_file ( $ request -> image , 'brand' ) ; $ data [ 'image' ] = $ image ; File :: delete ( $ brand -> image ) ; } if ( $ brand -> update ( $ data ) ) { return Helper :: response_with_data ( Brand :: query ( ) -> find ( $ brand -> id ) , false ) ; } return Helper :: response_with_data ( null , true ) ; }
Update the specified resource in storage.
Update the specified resource in storage .