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


PHP Tag::createAndReturnArrayOfTagIds方法代码示例

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


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

示例1: postEdit

 public function postEdit($id, Request $request)
 {
     $photo = Photo::with('tags')->find($id);
     if (!$photo) {
         return redirect()->back()->withError('Photo not found.');
     }
     $validation = Validator::make($request->all(), ['title' => 'required|min:3', 'photo' => 'image', 'user_id' => 'required|integer|exists:users,id', 'tags' => 'required']);
     if ($validation->fails()) {
         return redirect()->back()->withInput()->withErrors($validation);
     }
     $isFileUploaded = $request->hasFile('photo');
     if ($isFileUploaded) {
         //First, delete the old photos and all sizes using Croppa
         Croppa::delete(public_path() . '/uploads/' . $photo->image);
         //Then Upload the image and return the filename
         $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 ($isFileUploaded && $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 tag data.
                     $tagIds = array_unique(array_merge($tagIds, Tag::createAndReturnArrayOfTagIds($exif['IFD0']['Keywords'], ';')));
                 }
             }
         }
     }
     //Tag Stuff end
     $photo->user_id = $request->get('user_id');
     $photo->title = $request->get('title');
     if ($isFileUploaded) {
         $photo->image = $upload['filename'];
     }
     $photo->save();
     //Now, sync all the associated tags
     $photo->tags()->sync($tagIds);
     return redirect()->back()->withSuccess('Photo updated successfully!');
 }
开发者ID:hugoleodev,项目名称:WhatTheTag,代码行数:44,代码来源:PhotoController.php

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