當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。