函数str_slug已弃用,无法正常工作,我该怎么办?

时间:2019-08-04 01:01:33

标签: laravel-5.8

我试图使用Str_slug,但是在laravel 5.8中不起作用。 我正在使用PhpStorm最新版本。

$ product-> slug = Str_slug('$ request-> title');

Check the image for more

public function ProductStore(StoreValidation $request){
    $product = new product();
    $product->category_id = 1;
    $product->brand_id = 1;
    $product->title = $request->title;
    $product->desc = $request->desc;
    $product->slug = Str_slug('$request->title');
    $product->quantity = $request->quantity;
    $product->price = $request->price;
    $product->offer_price = $request->offer;
    $product->status = 1;
    $product->admin_id = 1;
    // Saving Product information into product table
    $product->save();

    if ($request->hasFile('uploadFile')){
        $image = $request->file('uploadFile');
        $img = time() . '.' . $image->getClientOriginalExtension();
        $location = public_path('image/product/' .$img);

        $img_ins = Image::make($image)->resize(220,294);
        $img_ins->save($location);

        $product_img = new product_image();
        $product_img->product_id = $product->id;
        $product_img->image_name = $img;

        $product_img->save();
    }

    return redirect()->route('admin_panel.pages.admin-addProduct');
}

1 个答案:

答案 0 :(得分:0)

您应该使用Str::slug()(Illuminate \ Support \ Str)而不是不推荐使用的str_slug()

https://laravel.com/docs/5.8/helpers#method-str-slug