app/Http/Controllers/Admin/GoodsController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $request->validate([
            'goods_name' => 'required|unique:goods|regex:/^[\x{4e00}-\x{9fa5}\w]{2,50}$/u',
            'goods_price' => 'required|numeric',
            'goods_num' => 'required|numeric|regex:/^\d{1,8}$/',
            'goods_number' => 'required',
        ],[
            'goods_name.required' => '商品名称必填！',
            'goods_name.unique' => '商品名称已存在！',
            'goods_name.regex' => '商品名称格式错误！',
            'goods_price.required' => '商品价格必填！',
            'goods_price.numeric' => '商品价格必须是数字！',
            'goods_num.required' => '商品库存必填！',
            'goods_numeric' => '商品库存必须是数字！',
            'goods_num.regex' => '商品库存不得超过8位！',
            'goods_number.required' => '商品货号必填!',
        ]);
        $post = request()->except(['_token']);
        dump($post);
        if($request->hasFile('goods_logo')){
            $post['goods_logo'] = $this->upload('goods_logo');
        }
        if(isset($post['goods_imgs'])){
            $imgs = $this->Moreupload('goods_imgs');
            $post['goods_imgs'] = implode('|',$imgs);
        }
        $res = DB::table('goods')->insert($post);
        if($res){
            return redirect('/goods');
        }
    }
public function store ( Request $ request ) { $ request -> validate ( [ 'goods_name' => 'required|unique:goods|regex:/^[\x{4e00}-\x{9fa5}\w]{2,50}$/u' , 'goods_price' => 'required|numeric' , 'goods_num' => 'required|numeric|regex:/^\d{1,8}$/' , 'goods_number' => 'required' , ] , [ 'goods_name.required' => '商品名称必填！', 'goods_name.unique' => '商品名称已存在！', 'goods_name.regex' => '商品名称格式错误！', 'goods_price.required' => '商品价格必填！', 'goods_price.numeric' => '商品价格必须是数字！', 'goods_num.required' => '商品库存必填！', 'goods_numeric' => '商品库存必须是数字！', 'goods_num.regex' => '商品库存不得超过8位！', 'goods_number.required' => '商品货号必填!', ] ) ; $ post = request ( ) -> except ( [ '_token' ] ) ; dump ( $ post ) ; if ( $ request -> hasFile ( 'goods_logo' ) ) { $ post [ 'goods_logo' ] = $ this -> upload ( 'goods_logo' ) ; } if ( isset ( $ post [ 'goods_imgs' ] ) ) { $ imgs = $ this -> Moreupload ( 'goods_imgs' ) ; $ post [ 'goods_imgs' ] = implode ( '|' , $ imgs ) ; } $ res = DB :: table ( 'goods' ) -> insert ( $ post ) ; if ( $ res ) { return redirect ( '/goods' ) ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .
//$post = request()->only(['_token','goods_logo']); //$goods_name = $request->goods_name; //dd($post); //if($request->hasFile('brand_logo')){ //dump($post); //dd($request->file('goods_logo')->isValid()); //上传文件