app/Http/Controllers/ProductController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return false|\Illuminate\Http\Response|string
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(StoreProductRequest $request)
    {
        if ($request->validated()){
            Product::create([
                'title'=>$request->validated()['title'],
                'price'=>$request->validated()['price'],
                'info'=>$request->validated()['info'],
                'description'=>$request->validated()['description'],
                'image'=>$request->file('image')->storePublicly('public/thumbnails'),
                'user_id'=>auth()->user()->id,
            ]);
            $product = Product::where('title',$request->validated()['title'])->firstOrFail();
            foreach ($request->file('images') as $image)
            {
                $product->Slides()->create([
                    'name'=>$image->storePublicly('public/slides'),
                ]);
            }
            $product->Category()->sync($request->input('categories'));
            $product->tag()->sync($request->input('tags'));
            return redirect()->route('product.index')->with('message','Product Create Successfully');
        }else{
            return redirect()->route('product.create')->withErrors($request->validated());
        }
    }
public function store ( StoreProductRequest $ request ) { if ( $ request -> validated ( ) ) { Product :: create ( [ 'title' => $ request -> validated ( ) [ 'title' ] , 'price' => $ request -> validated ( ) [ 'price' ] , 'info' => $ request -> validated ( ) [ 'info' ] , 'description' => $ request -> validated ( ) [ 'description' ] , 'image' => $ request -> file ( 'image' ) -> storePublicly ( 'public/thumbnails' ) , 'user_id' => auth ( ) -> user ( ) -> id , ] ) ; $ product = Product :: where ( 'title' , $ request -> validated ( ) [ 'title' ] ) -> firstOrFail ( ) ; foreach ( $ request -> file ( 'images' ) as $ image ) { $ product -> Slides ( ) -> create ( [ 'name' => $ image -> storePublicly ( 'public/slides' ) , ] ) ; } $ product -> Category ( ) -> sync ( $ request -> input ( 'categories' ) ) ; $ product -> tag ( ) -> sync ( $ request -> input ( 'tags' ) ) ; return redirect ( ) -> route ( 'product.index' ) -> with ( 'message' , 'Product Create Successfully' ) ; } else { return redirect ( ) -> route ( 'product.create' ) -> withErrors ( $ request -> validated ( ) ) ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .
// //