app/Http/Controllers/Dashboard/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)
    {
        $rules = [
            'category_id' => 'required'
        ];
        foreach (config('translatable.locales') as $locale) {
            $rules += [$locale . '.name' => 'required|unique:product_translations,name'];
            $rules += [$locale . '.description' => 'required'];
        }
        $rules += [
            'purchase_price' => 'required',
            'sale_price' => 'required',
            'stock' => 'required',
            'image' => 'required|mimes:jpg,bmp,png',
        ];
        $request->validate($rules);
        $request_data = $request->all();
        if ($request->image) {
            Image::make($request->image)
                ->resize(300, null, function ($constraint) {
                    $constraint->aspectRatio();
                })
                ->save(public_path('uploads/product_images/' . $request->image->hashName()));
            $request_data['image'] = $request->image->hashName();
        }
        Product::create($request_data);
        session()->flash('success', __('site.added_successfully'));
        return redirect()->route('dashboard.products.index');
    }
public function store ( Request $ request ) { $ rules = [ 'category_id' => 'required' ] ; foreach ( config ( 'translatable.locales' ) as $ locale ) { $ rules += [ $ locale . '.name' => 'required|unique:product_translations,name' ] ; $ rules += [ $ locale . '.description' => 'required' ] ; } $ rules += [ 'purchase_price' => 'required' , 'sale_price' => 'required' , 'stock' => 'required' , 'image' => 'required|mimes:jpg,bmp,png' , ] ; $ request -> validate ( $ rules ) ; $ request_data = $ request -> all ( ) ; if ( $ request -> image ) { Image :: make ( $ request -> image ) -> resize ( 300 , null , function ( $ constraint ) { $ constraint -> aspectRatio ( ) ; } ) -> save ( public_path ( 'uploads/product_images/' . $ request -> image -> hashName ( ) ) ) ; $ request_data [ 'image' ] = $ request -> image -> hashName ( ) ; } Product :: create ( $ request_data ) ; session ( ) -> flash ( 'success' , __ ( 'site.added_successfully' ) ) ; return redirect ( ) -> route ( 'dashboard.products.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .