app/Http/Controllers/Admin/ProductController.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)
    {
        $rule=[
            'name' => 'required|string|min:2|max:50|unique:products',
            'description' => 'required|string|min:2|max:255',
            'extract' => 'required|string|min:2|max:255',
            'price' => 'required|numeric|between:0,9999999999.99',
            'quantity'=> 'required',
            'foto' => 'image',
        ];
        $this->validate($request, $rule);
        $products=Product::create([
            'name'=>$request->get('name'),
            'slug'=>str_slug($request->get('name')),
            'description'=>$request->get('description'),
            'quantity'=>$request->get('quantity'),
            'extract'=>$request->get('extract'),
            'price'=>$request->get('price'),
            'category_id'=>$request->get('category_id'),
        ]);
        Foto::create([
            'ruta'=> $request -> foto-> store(''),
            'product_id' => $products->id,
        ]);
        return redirect()->route('index-produ');
    }
public function store ( Request $ request ) { $ rule = [ 'name' => 'required|string|min:2|max:50|unique:products' , 'description' => 'required|string|min:2|max:255' , 'extract' => 'required|string|min:2|max:255' , 'price' => 'required|numeric|between:0,9999999999.99' , 'quantity' => 'required' , 'foto' => 'image' , ] ; $ this -> validate ( $ request , $ rule ) ; $ products = Product :: create ( [ 'name' => $ request -> get ( 'name' ) , 'slug' => str_slug ( $ request -> get ( 'name' ) ) , 'description' => $ request -> get ( 'description' ) , 'quantity' => $ request -> get ( 'quantity' ) , 'extract' => $ request -> get ( 'extract' ) , 'price' => $ request -> get ( 'price' ) , 'category_id' => $ request -> get ( 'category_id' ) , ] ) ; Foto :: create ( [ 'ruta' => $ request -> foto -> store ( '' ) , 'product_id' => $ products -> id , ] ) ; return redirect ( ) -> route ( 'index-produ' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .