示例#1
0
 public function results(Request $request)
 {
     $type = $request->input('type');
     $query = $request->input('query');
     if ($type == 'user') {
         $results = User::where('username', 'LIKE', '%' . $query . '%')->paginate(20);
     } elseif ($type == 'reply') {
         $results = Reply::where('body_original', 'LIKE', '%' . $query . '%')->paginate(20);
     } elseif ($type == 'topic') {
         $results = Topic::where('body_original', 'LIKE', '%' . $query . '%')->paginate(20);
     } elseif ($type == 'status') {
         $results = Status::where('body_original', 'LIKE', '%' . $query . '%')->paginate(20);
     }
     return view('search.results', compact('type', 'query', 'results'));
 }
示例#2
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($slug)
 {
     $topic = Topic::where('slug', $slug)->firstOrFail();
     if ($topic->node->parent_node) {
         $expandable = $topic->node->parent_node;
     } else {
         $expandable = $topic->node_id;
     }
     $node = $topic->node;
     if (Auth::check()) {
         $replies = $topic->replies()->lists('id');
         // dd(Auth::user()->notifications()->whereIn('object_id', $replies)->where('object_type', 'reply')->get());
         Auth::user()->notifications()->whereIn('object_id', $replies)->where('object_type', 'reply')->update(['read_at' => new \DateTime()]);
         //bust da cache
         Cache::forget(Auth::user()->id . '_notification_count');
     }
     //padidina view counteri.
     $topic->increment('view_count');
     return view('topic.show', compact('topic', 'expandable', 'node'));
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Topic::where('vote_count', '<', '0')->update(['vote_count' => 0]);
     Reply::where('vote_count', '<', '0')->update(['vote_count' => 0]);
 }
示例#4
0
文件: Topic.php 项目: PovilasLT/maze
 public function getSlugAttribute($value)
 {
     if (!$value) {
         $value = $this->id . '-' . S::slugify($this->title);
         $nodes = Topic::where('slug', $value);
         if ($nodes->count() > 0) {
             $value = $this->id . '-' . $value;
             $this->slug = $value;
             $this->save();
             return $value;
         } else {
             $this->slug = $value;
             $this->save();
             return $value;
         }
     } else {
         return $value;
     }
 }