コード例 #1
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index($cat_id)
 {
     $parent = Category::find($cat_id)->parentCategory()->get();
     $current = Category::find($cat_id);
     $categories = Category::find($cat_id)->subCategories()->get();
     $posts = Category::find($cat_id)->posts()->get();
     return view('user.posts.index', ['posts' => $posts, 'categories' => $categories, 'parent' => $parent, 'current' => $current->toArray()]);
 }
コード例 #2
0
 /**
  * get the specific category and display its posts
  *
  * @return \Illuminate\View\View
  */
 public function getView($category_id)
 {
     $cat = Category::find($category_id);
     $child = Category::where('parent_id', $category_id)->get();
     $states = State::all();
     $posts = null;
     if (count($cat->subCategories->toArray()) > 0) {
         //$posts = DB::select('SELECT * FROM posts WHERE category_id IN (SELECT id FROM categories WHERE parent_id = ? ORDER BY published_at DESC)', [$category_id]);
         $cats = Category::where('parent_id', $category_id)->lists('id');
         $posts = Post::whereIn('category_id', $cats)->orderBy('published_at', 'desc')->paginate(config('traydes.posts_per_page'));
     } else {
         //$posts = $cat->posts;
         $posts = Post::where('category_id', $category_id)->orderBy('published_at', 'desc')->paginate(config('traydes.posts_per_page'));
     }
     return view('index.view', ['posts' => $posts, 'child' => $child, 'states' => $states]);
 }
コード例 #3
0
 /**
  * displaying the form for new posting
  *
  * @param Request $request
  * @return \Illuminate\View\View
  */
 public function getNew(Request $request)
 {
     $req = $request->get('c');
     $categories = null;
     $template = ['user.posts.templates.index', 'user.posts.templates.form'];
     $index = 0;
     if ($req != null) {
         $category = Category::find($req);
         //            dd($category->subCategories->count());
         if (count($category) > 0) {
             //not empty
             $categories = Category::where('parent_id', '=', $req)->get();
         }
         if ($category->subCategories->count() > 0) {
             $index = 0;
         } else {
             $index = 1;
         }
         return view('user.posts.create', ['categories' => $categories, 'category_id' => (int) $req, 'template' => $template[$index]]);
     }
     $categories = Category::where('parent_id', '=', 0)->get();
     return view('user.posts.create', ['categories' => $categories, 'template' => $template[$index]]);
 }
コード例 #4
0
 /**
  * get the category object in json format
  *
  * @param $id
  * @return mixed
  */
 public function getApiCategory($id)
 {
     $category = Category::find($id);
     return $category;
 }