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(ProductRequest $request)
    {
        $dados =$request->all();
        $imagens =$request->photos;
        $store = Auth::user()->store;
       $products = $store->products()->create($dados);
       $products->categories()->sync($dados['categories']);
       if($request->hasFile('photos'))
       {
         $fotos = $this->uploadImages($imagens,'image');
         $products->photos()->createMany($fotos);
       }
        flash('Produtos inseridos com sucesso!')->success();
        return redirect()->route('admin.products.index');
    }
public function store ( ProductRequest $ request ) { $ dados = $ request -> all ( ) ; $ imagens = $ request -> photos ; $ store = Auth :: user ( ) -> store ; $ products = $ store -> products ( ) -> create ( $ dados ) ; $ products -> categories ( ) -> sync ( $ dados [ 'categories' ] ) ; if ( $ request -> hasFile ( 'photos' ) ) { $ fotos = $ this -> uploadImages ( $ imagens , 'image' ) ; $ products -> photos ( ) -> createMany ( $ fotos ) ; } flash ( 'Produtos inseridos com sucesso!' ) -> success ( ) ; return redirect ( ) -> route ( 'admin.products.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .