本文整理汇总了PHP中app\Tag::whereIn方法的典型用法代码示例。如果您正苦于以下问题:PHP Tag::whereIn方法的具体用法?PHP Tag::whereIn怎么用?PHP Tag::whereIn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Tag
的用法示例。
在下文中一共展示了Tag::whereIn方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: syncTags
/**
* Sync tag relation adding new tags as needed
*
* @param array $tags
*/
public function syncTags(array $tags)
{
Tag::addNeededTags($tags);
if (count($tags)) {
$this->tags()->sync(Tag::whereIn('tag', $tags)->lists('id')->all());
return;
}
$this->tags()->detach();
}
示例2: syncTags
/**
* Sync tag relation adding new tags as needed
* @param array $tags
*/
public function syncTags(array $tags)
{
Tag::addNeededTags($tags);
if (count($tags)) {
// After method sync() is complete, only the IDs in the array $tags will exist
// in the intermediate table:post_tag_pivot
$this->tags()->sync(Tag::whereIn('tag', $tags)->pluck('id')->all());
return;
}
$this->tags()->detach();
}
示例3: postStore
public function postStore($id = null)
{
// ---------------------------------------- HANDLE REQUEST ----------------------------------------
// handle id
if (!is_null($id)) {
$data = $this->model->findorfail($id);
} else {
$data = $this->model->newInstance();
}
// ---------------------------------------- CHECK TAG ----------------------------------------
$tags_in_db = \App\Tag::whereIn('tag', Input::get('tags'))->get();
if (!$tags_in_db) {
$tags_in_db = new Collection();
}
foreach (Input::get('tags') as $x) {
if (!$tags_in_db->where('tag', $x)->first()->id) {
$new_tag = new \App\Tag(['tag' => $x]);
if (!$new_tag->save()) {
dd($new_tag->getErrors());
}
$tags_in_db->push($new_tag);
}
}
// ---------------------------------------- HANDLE SAVE ----------------------------------------
$input = Input::all();
if (!empty($input['published_at'])) {
$input['published_at'] = \Carbon\Carbon::createFromFormat('d/m/Y H:i', $input['published_at'])->format('Y-m-d H:i:s');
} else {
$input['published_at'] = null;
}
unset($input['longlat']);
$input['tag_ids'] = $tags_in_db->pluck('id')->toArray();
$data->fill($input);
if ($data->save()) {
if (!$this->save_required_images($data, $input)) {
return redirect()->back()->withInput()->withErrors($data->getErrors());
}
return redirect()->route('admin.' . $this->view_name . '.show', ['id' => $data->id])->with('alert_success', '"' . $data->{$data->getNameField()} . '" has been saved successfully');
} else {
return redirect()->back()->withInput()->withErrors($data->getErrors());
}
}
示例4: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request)
{
$validator = Validator::make($request->all(), ['key' => 'required|size:128', 'email' => 'email|required|max:254']);
$redirectToEditUrl = function () use($request) {
return Redirect::to('/subscription/edit?email=' . $request->input('email') . '&key=' . $request->input('key'));
};
if ($validator->fails()) {
$redirectToEditUrl();
}
$subscription = Subscription::with('topics')->where('email', $request->input('email'))->where('key', $request->input('key'))->firstOrFail();
$subscription->topics()->detach();
if (!empty($request->input('topics')) && is_array($request->input('topics'))) {
$tags = Tag::whereIn('id', array_keys($request->input('topics')))->get();
if (count($tags) != count(array_keys($request->input('topics')))) {
Session::flash('errors', 'Woops. Something went badly wrong.');
return $redirectToEditUrl();
}
$subscription->topics()->saveMany($tags->all());
}
$subscription->save();
Session::flash('status', 'Saved.');
return $redirectToEditUrl();
}
示例5: deltag
public function deltag(Request $request)
{
$id = (array) $request->id;
if (Tag::whereIn('id', $id)->delete()) {
return response()->json(200);
} else {
return response()->json(404);
}
}
示例6: restoreTags
public function restoreTags(Article $article)
{
$tagIds = $article->tags->lists('id');
Tag::whereIn('id', $tagIds)->increment('count');
}
示例7: syncTags
/**
* Sync Tag với tiện ích thêm mới nếu Tag chưa tồn tại
*
* @param array $tags
* @return array
*/
public function syncTags($tags)
{
$allTagsFound = Tag::whereIn('id', $tags)->lists('id')->toArray();
// Mảng Sync cần loại giá trị tag chưa tồn tại
$tagsSync = array_intersect($tags, $allTagsFound);
// Sau đó nếu tag chưa tồn tại, cần thêm mới tag vào db, và trả lại id tương ứng để đưa vào mảng Sync
foreach (array_diff($tags, $allTagsFound) as $tag) {
$tagsSync[] = Tag::create(['name' => $tag])->id;
}
return $this->tags()->sync($tagsSync);
}