Exemplo n.º 1
0
 public function profile($name)
 {
     $user = User::where('name', $name)->with(['posts' => function ($q) {
         $q->orderBy('created_at', 'desc');
     }])->first();
     if (Request::wantsJson()) {
         $user->clickSum = Post::where('user_id', $user->id)->sum('clickNum');
         $user->approveSum = DB::table('approves')->sum('user_id');
         return response()->json($user, 200);
     }
     return view('user.profile', compact('user'));
 }
Exemplo n.º 2
0
 function getPosts()
 {
     $c = Input::get('c');
     $s = Input::get('s');
     if ($c == 0 && $s === '') {
         $posts = Post::with('category')->with('user')->with('tags')->with('approves')->orderBy('id', 'desc')->paginate(15);
     } else {
         if ($s !== '' && $c == 0) {
             $posts = Post::with('category')->with('user')->with('tags')->with('approves')->where('title', 'LIKE', '%' . $s . '%')->orderBy('id', 'desc')->paginate(15);
         } else {
             $posts = Post::with('category')->with('user')->with('tags')->with('approves')->where('category_id', $c)->where('title', 'LIKE', '%' . $s . '%')->orderBy('id', 'desc')->paginate(15);
         }
     }
     return response()->json($posts);
 }
Exemplo n.º 3
0
 public function addNewShare(NewShareRequest $request)
 {
     $post = Post::create(['user_id' => Auth::user()->id, 'title' => $request->input('share.title'), 'url' => $request->input('share.url'), 'category_id' => $request->input('share.category')]);
     $post->tags()->sync($request->input('share.tags'));
 }
Exemplo n.º 4
0
 public function getAll()
 {
     $books = Post::with('category')->where('category_id', '=', '2')->get();
     return response()->json($book);
 }