【发布时间】:2017-04-03 23:33:46
【问题描述】:
我正在寻找一些将关键字从帖子变成内部链接的代码示例。
在帖子表中,我有正文属性,其中是帖子的文本。我制作了额外的表格“关键字”,其中单词和 URL 属性。
所以我需要脚本,它会自动识别添加到表“关键字”中的单词,并在帖子文本中找到这个单词并将这个单词转换为超链接。请大家帮帮我好吗?
use App\Post;
use App\Category;
use App\Keyword;
public function getSingle($slug) {
// fetch from the DB based on slug
$categoriesall = Category::all();
$post = Post::where('slug', '=', $slug)->first();
// return the view and pass in the post object
return view('news.single')->withPost($post)->withCategoriesall($categoriesall);
}
【问题讨论】: