本文整理匯總了PHP中app\models\Tag::whereTag方法的典型用法代碼示例。如果您正苦於以下問題:PHP Tag::whereTag方法的具體用法?PHP Tag::whereTag怎麽用?PHP Tag::whereTag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\models\Tag
的用法示例。
在下文中一共展示了Tag::whereTag方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: showPost
public function showPost($slug, Request $request)
{
$post = Post::with('tags')->whereSlug($slug)->firstOrFail();
$tag = $request->get('tag');
if ($tag) {
$tag = Tag::whereTag($tag)->firstOrFail();
}
return view($post->layout, compact('post', 'tag'));
}
示例2: store
/**
* Create a post.
*
* @param array $inputs
* @param int $user_id
* @return void
*/
public function store($inputs, $user_id)
{
$post = $this->savePost(new $this->model(), $inputs, $user_id);
// Tags gestion
if (array_key_exists('tags', $inputs) && $inputs['tags'] != '') {
$tags = explode(',', $inputs['tags']);
foreach ($tags as $tag) {
$tag_ref = $this->tag->whereTag($tag)->first();
if (is_null($tag_ref)) {
$tag_ref = new $this->tag();
$tag_ref->tag = $tag;
$post->tags()->save($tag_ref);
} else {
$post->tags()->attach($tag_ref->id);
}
}
}
// Maybe purge orphan tags...
}
示例3: update
/**
* Update a post.
*
* @param array $inputs
* @param App\Models\Post $post
* @return void
*/
public function update($inputs, $post)
{
$post = $this->savePost($post, $inputs);
// Tag control
$tags_id = [];
if (array_key_exists('tags', $inputs) && $inputs['tags'] != '') {
$tags = explode(',', $inputs['tags']);
foreach ($tags as $tag) {
$tag_ref = $this->tag->whereTag($tag)->first();
if (is_null($tag_ref)) {
$tag_ref = new $this->tag();
$tag_ref->tag = $tag;
$tag_ref->save();
}
array_push($tags_id, $tag_ref->id);
}
}
$post->tags()->sync($tags_id);
}