app/Http/Controllers/BrandController.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)
    {
        $validated = $request->validate([
            'brand_name' => 'required|unique:brands|min:4',
            'brand_image' => 'required|mimes:jpg,jpeg,png',
        ],
        [
            'brand_name.required' => 'Please Input Brand Name',
            'brand_image.min' => 'Brand longer than 4 Characters',
        ]
    );
        $brand_image = $request->file('brand_image');
        $name_gen = hexdec(uniqid()).'.'.$brand_image->getClientOriginalExtension();
        $last_img = 'image/brand/'.$name_gen;
        Image::make($brand_image)->resize(300,200)->save($last_img);
        Brand::insert([
            'brand_name' => $request->brand_name,
            'brand_image' => $last_img,
            'created_at' => Carbon::now()
        ]);
        return redirect()->back()->with('success', 'Category Inserted Succesfully!');
    }
public function store ( Request $ request ) { $ validated = $ request -> validate ( [ 'brand_name' => 'required|unique:brands|min:4' , 'brand_image' => 'required|mimes:jpg,jpeg,png' , ] , [ 'brand_name.required' => 'Please Input Brand Name' , 'brand_image.min' => 'Brand longer than 4 Characters' , ] ) ; $ brand_image = $ request -> file ( 'brand_image' ) ; $ name_gen = hexdec ( uniqid ( ) ) . '.' . $ brand_image -> getClientOriginalExtension ( ) ; $ last_img = 'image/brand/' . $ name_gen ; Image :: make ( $ brand_image ) -> resize ( 300 , 200 ) -> save ( $ last_img ) ; Brand :: insert ( [ 'brand_name' => $ request -> brand_name , 'brand_image' => $ last_img , 'created_at' => Carbon :: now ( ) ] ) ; return redirect ( ) -> back ( ) -> with ( 'success' , 'Category Inserted Succesfully!' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
/**
         * as category_name is a field name
         * unique:categories, categories as table name
         * */ // image name generator // $brand_image = $request->file('brand_image'); // $name_gen = hexdec(uniqid()); // $img_ext = strtolower($brand_image->getClientOriginalExtension()); // $img_name = $name_gen.'.'.$img_ext; // //upload image // $up_location = 'image/brand/'; // $last_img = $up_location.$img_name; // $brand_image->move($up_location,$img_name); // Image Intervention