当前位置: 首页>>代码示例>>PHP>>正文


PHP Tag::firstOrNew方法代码示例

本文整理汇总了PHP中app\Tag::firstOrNew方法的典型用法代码示例。如果您正苦于以下问题:PHP Tag::firstOrNew方法的具体用法?PHP Tag::firstOrNew怎么用?PHP Tag::firstOrNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\Tag的用法示例。


在下文中一共展示了Tag::firstOrNew方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addTags

 public function addTags($lead_id, Request $tags)
 {
     foreach ($tags as $tag) {
         $item = Tag::firstOrNew(['name' => $tag, 'lead_id' => $lead_id]);
     }
     return \Response::make('OK', 200);
 }
开发者ID:bunsha,项目名称:gazingle,代码行数:7,代码来源:TagsController.php

示例2: postEdit

 public function postEdit(Request $request)
 {
     $userID = Auth::user()->id;
     //Make sure title and tags are provided
     $validator = $this->editValidator($request->all());
     if ($validator->fails()) {
         $this->throwValidationException($request, $validator);
     }
     $tags = explode(",", $request->tags);
     try {
         //Find the bookmark with ID=$id
         $bookmark = Bookmark::findOrFail($request->id);
         if ($bookmark->owner_id != $userID) {
             return "This is not your bookmark";
         }
         //Update the bookmark's title
         $bookmark->title = $request->page_title;
         $bookmark->colour = $request->colour;
         $bookmark->save();
         //Now create a new tag object for each of the tags
         //Only if it doesn't already exist in tags
         foreach ($tags as $tag_name) {
             // Retrieve the tag by the attributes, or instantiate a new instance...
             $tag = Tag::firstOrNew(array('tag_name' => $tag_name));
             $tag->save();
             $bookmarkTag = BookmarkTag::firstOrNew(array('bookmark_id' => $bookmark->bookmark_id, 'tag_id' => $tag->tag_id));
             $bookmarkTag->save();
         }
     } catch (ModelNotFoundException $e) {
         return "Bookmark not found: " . $e->getMessage();
     }
     return redirect($this->bookmarksPath);
 }
开发者ID:kings0c,项目名称:bookmarquee,代码行数:33,代码来源:BookmarksController.php

示例3: update

 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $token = $request->header('token');
     $user = $this->api ? User::where('token', $token)->first() : Auth::user();
     $userID = isset($user) ? $user->id : 0;
     if (!$userID) {
         return $this->api ? response()->json(['data' => ['message' => 'Not logged in']], 401) : redirect(route('login'));
     }
     $post = PostBlog::whereRaw('id = ? AND userID = ?', [$id, $userID])->first();
     $fields = $request->all();
     $validator = Validator::make($fields, ['name' => 'required', 'description' => 'required', 'text' => 'required']);
     if ($validator->fails()) {
         if (!$this->api) {
             return redirect(route('edit', ['id' => $id]))->withErrors($validator);
         } else {
             return response()->json(['data' => ['errors' => $validator->errors()->getMessages()]], 400);
         }
     }
     $post->userID = $userID;
     $post->name = $fields['name'];
     $post->description = $fields['description'];
     $post->text = $fields['text'];
     $post->active = isset($fields['active']) ? 1 : 0;
     $post->save();
     $tags = explode(',', $fields['tags']);
     foreach ($tags as $tag) {
         $tagObj = Tag::firstOrNew(['tagName' => $tag]);
         $tagObj->save();
         PostBlogTag::firstOrNew(['postID' => $post->id, 'tagID' => $tagObj->id])->save();
     }
     return $this->api ? response()->json(['data' => ['message' => 'Edit successfully']], 200) : redirect(route('home'));
 }
开发者ID:sava90,项目名称:laravel,代码行数:39,代码来源:Blog.php


注:本文中的app\Tag::firstOrNew方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。