app/Http/Controllers/CategoriesController.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)
    {
        $data=request()->validate([
           'name'=>'required|unique:categories,name',
           'categories_type'=>'',
           'categories_size'=>'',
           'categories_image'=>'required',
            'categories_title'=>'',
            'button_name'=>'',
            'button_icon'=>'',
        ]);
        $id=auth()->user()->id;
        $imagePath = request('categories_image')->store('CategoriesImage', 'public');
        $image = Image::make("storage/{$imagePath}")->fit(350, 380);
        $category=Categories::create([
            'name'=>$data['name'],
            'categories_type'=>$data['categories_type'],
            'categories_size'=>$data['categories_size'],
            'categories_image'=>$imagePath,
            'categories_title'=>$data['categories_title'],
            'button_name'=>$data['button_name'],
            'button_icon'=>$data['button_icon'],
            'user_id'=>$id
        ]);
        return redirect('/categories');
    }
public function store ( Request $ request ) { $ data = request ( ) -> validate ( [ 'name' => 'required|unique:categories,name' , 'categories_type' => '' , 'categories_size' => '' , 'categories_image' => 'required' , 'categories_title' => '' , 'button_name' => '' , 'button_icon' => '' , ] ) ; $ id = auth ( ) -> user ( ) -> id ; $ imagePath = request ( 'categories_image' ) -> store ( 'CategoriesImage' , 'public' ) ; $ image = Image :: make ( " storage/ { $ imagePath } " ) -> fit ( 350 , 380 ) ; $ category = Categories :: create ( [ 'name' => $ data [ 'name' ] , 'categories_type' => $ data [ 'categories_type' ] , 'categories_size' => $ data [ 'categories_size' ] , 'categories_image' => $ imagePath , 'categories_title' => $ data [ 'categories_title' ] , 'button_name' => $ data [ 'button_name' ] , 'button_icon' => $ data [ 'button_icon' ] , 'user_id' => $ id ] ) ; return redirect ( '/categories' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .