app/Http/Controllers/BrandController.php
/**
     * Store a newly created resource in storage.
     *
     * @param Request $request
     * @return JsonResponse
     */
Store a newly created resource in storage.
@param Request $request
@return JsonResponse
Store a newly created resource in storage . @param Request $request @return JsonResponse
public function store(Request $request)
    {
        $request->validate(
            [
                'name' => 'required',
                'shop_id' => 'nullable|exists:shops,id'
            ]
        );
        $data['name'] = $request->name;
        $data['shop_id'] = $request->shop_id;
        $data['details'] = $request->details;
        $data['origin'] = $request->origin;
        if ($request->hasFile('image')) {
            $image = Helper::save_file($request->image, 'brand');
            $data['image']  = $image;
        }
        $brand = Brand::query()->create($data);
        if ($brand){
            return Helper::response_with_data($brand, false);
        }
        return Helper::response_with_data(null, true);
    }
public function store ( Request $ request ) { $ request -> validate ( [ 'name' => 'required' , 'shop_id' => 'nullable|exists:shops,id' ] ) ; $ data [ 'name' ] = $ request -> name ; $ data [ 'shop_id' ] = $ request -> shop_id ; $ data [ 'details' ] = $ request -> details ; $ data [ 'origin' ] = $ request -> origin ; if ( $ request -> hasFile ( 'image' ) ) { $ image = Helper :: save_file ( $ request -> image , 'brand' ) ; $ data [ 'image' ] = $ image ; } $ brand = Brand :: query ( ) -> create ( $ data ) ; if ( $ brand ) { return Helper :: response_with_data ( $ brand , false ) ; } return Helper :: response_with_data ( null , true ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .