コード例 #1
0
ファイル: Categories.php プロジェクト: richlove1/avc-october
 public function index_onDelete()
 {
     if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) {
         foreach ($checkedIds as $categoryId) {
             if (!($category = Category::find($categoryId))) {
                 continue;
             }
             $category->delete();
         }
         Flash::success('Successfully deleted those categories.');
     }
     return $this->listRefresh();
 }
コード例 #2
0
ファイル: Post.php プロジェクト: richlove1/avc-october
 /**
  * Lists posts for the front end
  * @param  array $options Display options
  * @return self
  */
 public function scopeListFrontEnd($query, $options)
 {
     /*
      * Default options
      */
     extract(array_merge(['page' => 1, 'perPage' => 30, 'sort' => 'created_at', 'categories' => null, 'category' => null, 'search' => '', 'published' => true], $options));
     $searchableFields = ['title', 'slug', 'excerpt', 'content'];
     if ($published) {
         $query->isPublished();
     }
     /*
      * Sorting
      */
     if (!is_array($sort)) {
         $sort = [$sort];
     }
     foreach ($sort as $_sort) {
         if (in_array($_sort, array_keys(self::$allowedSortingOptions))) {
             $parts = explode(' ', $_sort);
             if (count($parts) < 2) {
                 array_push($parts, 'desc');
             }
             list($sortField, $sortDirection) = $parts;
             if ($sortField == 'random') {
                 $sortField = DB::raw('RAND()');
             }
             $query->orderBy($sortField, $sortDirection);
         }
     }
     /*
      * Search
      */
     $search = trim($search);
     if (strlen($search)) {
         $query->searchWhere($search, $searchableFields);
     }
     /*
      * Categories
      */
     if ($categories !== null) {
         if (!is_array($categories)) {
             $categories = [$categories];
         }
         $query->whereHas('categories', function ($q) use($categories) {
             $q->whereIn('id', $categories);
         });
     }
     /*
      * Category, including children
      */
     if ($category !== null) {
         $category = Category::find($category);
         $categories = $category->getAllChildrenAndSelf()->lists('id');
         $query->whereHas('categories', function ($q) use($categories) {
             $q->whereIn('id', $categories);
         });
     }
     return $query->paginate($perPage, $page);
 }