當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Photo::tags方法代碼示例

本文整理匯總了PHP中app\Photo::tags方法的典型用法代碼示例。如果您正苦於以下問題:PHP Photo::tags方法的具體用法?PHP Photo::tags怎麽用?PHP Photo::tags使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\Photo的用法示例。


在下文中一共展示了Photo::tags方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: postNew

 public function postNew(Request $request)
 {
     $validation = Validator::make($request->all(), ['title' => 'required|min:3', 'photo' => 'required|image', 'tags' => 'required']);
     if ($validation->fails()) {
         return redirect()->back()->withInput()->withErrors($validation);
     }
     //Upload the image and return the filename and full path
     $upload = Photo::upload($request->file('photo'));
     //Tag Stuff
     //First, create(if needed) and return IDs of tags
     $tagIds = Tag::createAndReturnArrayOfTagIds($request->get('tags'));
     //If user wants to read the tags (keywords) from the file, then we need to fetch them from uploaded file.
     if ($request->has('read_tags_from_file')) {
         $exif = exif_read_data($upload['fullpath'], 'ANY_TAG', true);
         if ($exif) {
             if (array_key_exists('IFD0', $exif)) {
                 if (array_key_exists('Keywords', $exif['IFD0'])) {
                     //array_unique, because same tags may be on both the form and the file, but only one is added to the database
                     //Keywords are delimited by semicolon ( ; ) in the EXIF tag data.
                     $tagIds = array_unique(array_merge($tagIds, Tag::createAndReturnArrayOfTagIds($exif['IFD0']['Keywords'], ';')));
                 }
             }
         }
     }
     //Tag Stuff end
     $photo = new Photo();
     $photo->user_id = Auth::user()->id;
     $photo->title = $request->get('title');
     $photo->image = $upload['filename'];
     $photo->save();
     //Now attach the tags, since this is creating method, attach() is okay
     $photo->tags()->attach($tagIds);
     return redirect()->back()->withSuccess('Photo Created Successfully!');
 }
開發者ID:Mohit127,項目名稱:WhatTheTag,代碼行數:34,代碼來源:PhotoController.php


注:本文中的app\Photo::tags方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。