app/Http/Controllers/BranchController.php
/**
     * Update the specified resource in storage.
     *
     * @param Request $request
     * @param Branch $branch
     * @return JsonResponse
     */
Update the specified resource in storage.
@param Request $request
@param Branch $branch
@return JsonResponse
Update the specified resource in storage . @param Request $request @param Branch $branch @return JsonResponse
public function update(Request $request, Branch $branch)
    {
        $request->validate([
            'name' => "nullable",
            'shop_id' => 'nullable|exists:shops,id',
            'address' => '',
            'mobile' => '',
            'details' => ''
        ]);
        if ($request->hasFile('file')) {
            $image = Helper::save_file($request->file, 'branch');
            $request['image']  = $image;
        }
        $data = collect($request);
        if ($request->hasFile('file')) {
            $data->forget('file');
        }
        if ($branch->update($data->toArray()))
        {
            return Helper::response_with_data(Branch::query()->find($branch->id), false);
        }
        return Helper::response_with_data(null, true);
    }
public function update ( Request $ request , Branch $ branch ) { $ request -> validate ( [ 'name' => " nullable " , 'shop_id' => 'nullable|exists:shops,id' , 'address' => '' , 'mobile' => '' , 'details' => '' ] ) ; if ( $ request -> hasFile ( 'file' ) ) { $ image = Helper :: save_file ( $ request -> file , 'branch' ) ; $ request [ 'image' ] = $ image ; } $ data = collect ( $ request ) ; if ( $ request -> hasFile ( 'file' ) ) { $ data -> forget ( 'file' ) ; } if ( $ branch -> update ( $ data -> toArray ( ) ) ) { return Helper :: response_with_data ( Branch :: query ( ) -> find ( $ branch -> id ) , false ) ; } return Helper :: response_with_data ( null , true ) ; }
Update the specified resource in storage.
Update the specified resource in storage .