app/Http/Controllers/BranchController.php
/**
     * Store a newly created resource in storage.
     *
     * @param Request $request
     * @return JsonResponse|Response
     */
Store a newly created resource in storage.
@param Request $request
@return JsonResponse|Response
Store a newly created resource in storage . @param Request $request @return JsonResponse|Response
public function store(Request $request)
    {
        $request->validate([
            'name' => "required",
            'shop_id' => 'required',
            'address' => '',
            'mobile' => '',
            'details' => ''
        ]);
        if ($request->hasFile('file')) {
            $image = Helper::save_file($request->file, 'branch');
            $request['image']  = $image;
        }
        $data = collect($request);
        $data->forget('file')->toArray();
        $branch = Branch::query()->create($data->toArray());
        if ($branch)
        {
            return Helper::response_with_data($branch, false);
        }
        return Helper::response_with_data(null, true);
    }
public function store ( Request $ request ) { $ request -> validate ( [ 'name' => " required " , 'shop_id' => 'required' , 'address' => '' , 'mobile' => '' , 'details' => '' ] ) ; if ( $ request -> hasFile ( 'file' ) ) { $ image = Helper :: save_file ( $ request -> file , 'branch' ) ; $ request [ 'image' ] = $ image ; } $ data = collect ( $ request ) ; $ data -> forget ( 'file' ) -> toArray ( ) ; $ branch = Branch :: query ( ) -> create ( $ data -> toArray ( ) ) ; if ( $ branch ) { return Helper :: response_with_data ( $ branch , false ) ; } return Helper :: response_with_data ( null , true ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .