config/app/Http/Controllers/SupplierController.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([
            'supplier_name'=>'required|min:3',
            'supplier_brand'=>'required',
            'phone'=>'required|min:11|max:15',
            'email'=>'required',
        ],[
        ]);
        $supplier_slug = Str::of($request->supplier_name)->slug('-');
        $insert = Supplier::insertGetId([
            'supplier_name'=>$request->supplier_name,
            'supplier_brand'=>$request->supplier_brand,
            'address'=>$request->address,
            'phone'=>$request->phone,
            'email'=>$request->email,
            'supplier_slug'=>$supplier_slug,
            'created_at'=>Carbon::now()->toDateTimeString(),
        ]);
        if($request->hasFile('supplier_img')){
            $image = $request->file('supplier_img');
            $image_name = $supplier_slug.'('.$insert.')'.'-'.time().'.'.$image->getClientOriginalExtension();
            Image::make($image)->resize(250,250)->save(base_path('public/uploads/suppliers/'.$image_name));
            Supplier::where('id',$insert)->update([
                'supplier_img'=>$image_name,
                'updated_at'=>Carbon::now()->toDateTimeString(),
            ]);
        }
        if($insert){
            Session::flash('success','New supplier adder successfully.');
            return redirect('/admin/suppliers/create');
        }
        else{
            Session::flash('error','Something were wrong!');
            return redirect('/admin/suppliers/create');
        }
    }
public function store ( Request $ request ) { $ request -> validate ( [ 'supplier_name' => 'required|min:3' , 'supplier_brand' => 'required' , 'phone' => 'required|min:11|max:15' , 'email' => 'required' , ] , [ ] ) ; $ supplier_slug = Str :: of ( $ request -> supplier_name ) -> slug ( '-' ) ; $ insert = Supplier :: insertGetId ( [ 'supplier_name' => $ request -> supplier_name , 'supplier_brand' => $ request -> supplier_brand , 'address' => $ request -> address , 'phone' => $ request -> phone , 'email' => $ request -> email , 'supplier_slug' => $ supplier_slug , 'created_at' => Carbon :: now ( ) -> toDateTimeString ( ) , ] ) ; if ( $ request -> hasFile ( 'supplier_img' ) ) { $ image = $ request -> file ( 'supplier_img' ) ; $ image_name = $ supplier_slug . '(' . $ insert . ')' . '-' . time ( ) . '.' . $ image -> getClientOriginalExtension ( ) ; Image :: make ( $ image ) -> resize ( 250 , 250 ) -> save ( base_path ( 'public/uploads/suppliers/' . $ image_name ) ) ; Supplier :: where ( 'id' , $ insert ) -> update ( [ 'supplier_img' => $ image_name , 'updated_at' => Carbon :: now ( ) -> toDateTimeString ( ) , ] ) ; } if ( $ insert ) { Session :: flash ( 'success' , 'New supplier adder successfully.' ) ; return redirect ( '/admin/suppliers/create' ) ; } else { Session :: flash ( 'error' , 'Something were wrong!' ) ; return redirect ( '/admin/suppliers/create' ) ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .