예제 #1
0
파일: Tags.php 프로젝트: surahmans/blogtags
 protected function loadTags()
 {
     $query = Tag::with('posts');
     if (!$this->property('emptyTag')) {
         $query->has('posts', '>=', '1');
     }
     if ($take = intVal($this->property('results'))) {
         $query->take($take);
     }
     $query->listTags($this->property('sortOrder'));
     return $query->get();
 }
예제 #2
0
 /**
  * get tag id if exists or create it if not exists
  *
  * @return array
  */
 public function getSaveValue($value)
 {
     $tags = explode(",", implode(",", $value));
     $ids = [];
     foreach ($tags as $name) {
         if (empty($name)) {
             continue;
         }
         $created = Tag::firstOrCreate(['name' => $name]);
         $ids[] = $created->id;
     }
     return $ids;
 }
예제 #3
0
<?php

use Rahman\BlogTags\Models\Tag;
use RainLab\Blog\Models\Post;
/**
 * get available tags and assigned tags by post id
 */
Route::get('api/blog/post/{postId?}', ['as' => 'api.get.taglist', function ($postId = 0) {
    $availableTags = Tag::all()->lists('name');
    $assignedTags = Tag::whereHas('posts', function ($q) use($postId) {
        $q->where('id', $postId);
    })->lists('name');
    $response = ['assignedTags' => $assignedTags, 'availableTags' => $availableTags];
    return Response::json($response);
}]);
예제 #4
0
 protected function loadTag()
 {
     return Tag::where('slug', $this->property('slug'))->first();
 }