app/Http/Controllers/Admin/categoryController.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)
    {
        $validateData =$request->validate([
            'name' =>'required|unique:categories',
            'image' =>'required|image|mimes:png,jpg,jpeg'
        ]);
        $image = $request->image;
        $imgName=Str::slug($request->name).uniqid().'.'. $image->getClientOriginalExtension();
        if(!Storage::disk('public')->exists('category')){
            Storage::disk('public')->makeDirectory('category');
        }
        $image->storeAs('category',$imgName,'public');
        $categories= new categories;
        $categories->name=$request->name;
        $categories->slug= Str::slug($request->name) ;
        $categories->disc=$request->disc;
        $categories->image=$imgName;
        $categories->save();
        Toastr::success('Successfully', 'Category Created',["progressBar" => true,"timeOut"=> "1200",]) ;
        return redirect()->route('admin.category.index');
    }
public function store ( Request $ request ) { $ validateData = $ request -> validate ( [ 'name' => 'required|unique:categories' , 'image' => 'required|image|mimes:png,jpg,jpeg' ] ) ; $ image = $ request -> image ; $ imgName = Str :: slug ( $ request -> name ) . uniqid ( ) . '.' . $ image -> getClientOriginalExtension ( ) ; if ( ! Storage :: disk ( 'public' ) -> exists ( 'category' ) ) { Storage :: disk ( 'public' ) -> makeDirectory ( 'category' ) ; } $ image -> storeAs ( 'category' , $ imgName , 'public' ) ; $ categories = new categories ; $ categories -> name = $ request -> name ; $ categories -> slug = Str :: slug ( $ request -> name ) ; $ categories -> disc = $ request -> disc ; $ categories -> image = $ imgName ; $ categories -> save ( ) ; Toastr :: success ( 'Successfully' , 'Category Created' , [ " progressBar " => true , " timeOut " => " 1200 " , ] ) ; return redirect ( ) -> route ( 'admin.category.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .