【发布时间】:2021-06-13 04:26:39
【问题描述】:
我想为同一个标题创建独特的 slug。
示例 - www.xcv.com/ght-ghy/
示例 1 - www.xcv.com/ght-ghy-1/
这是我的控制器代码:
public function addPostDetails(Request $request) {
$postTitle = $request->postTitle;
$postDesc = $request->postDesc;
$postCat = $request->postCat;
$postTags = $request->tagid;
$tags = explode(",", $postTags);
$postglobid = date('y') . date('s') . $postCat . rand(0000, 9999);
$posturl = Str::slug($postTitle, '-');
$galImg = array();
$postimgnm = NULL;
if($postimg = $request->hasFile('postWallImage')) {
$postimg = $request->file('postWallImage');
$postimgnm = $postimg->getClientOriginalName();
$storeTo = public_path() . '/images/' . $postglobid;
File::makeDirectory($storeTo, $mode = 0777, true, true);
$postimg->move($storeTo, $postimgnm);
}
if($postimges = $request->hasFile('postImgGal')) {
$postimges = $request->file('postImgGal');
foreach($postimges as $imgs) {
$postimgnms = $imgs->getClientOriginalName();
$storeTo = public_path() . '/images/' . $postglobid . '/gallery/';
File::makeDirectory($storeTo, $mode = 0777, true, true);
$imgs->move($storeTo, $postimgnms);
array_push($galImg, $postimgnms);
}
}
$savecat = $this->savePostByCategory($postCat, $postglobid, 'createcat');
$savetag = $this->savePostByTag($tags, $postglobid, 'createtag');
$savepost = new Post;
$savepost->post_global_id = $postglobid;
$savepost->post_title = $postTitle;
$savepost->post_desc = $postDesc;
$savepost->post_img = $postimgnm;
$savepost->post_img_gal = json_encode($galImg);
$savepost->post_url = $posturl;
$savepost->save();
return redirect('/seo/viewallpost')->with('postSuccess', 'Blog has been Posted Successfully');
}
【问题讨论】:
标签: mysql laravel laravel-5.8