コード例 #1
0
 public function tag(Request $request)
 {
     $limit = $this->getLimit($request);
     /** @type Tag $tag */
     $tag = Tag::whereSlug($request->get('id'))->first();
     if (!$tag) {
         return $this->response()->noContent();
     }
     $quotes = $tag->quotes()->published()->orderBy('quotes.created_at', 'desc')->paginate($limit);
     return $this->response()->paginator($quotes, new QuoteTransformer());
 }
コード例 #2
0
 /**
  * Display a listing of the resource.
  *
  * @param \Illuminate\Http\Request $request
  *
  * @return \Quoterr\Http\Controllers\Response
  */
 public function index(Request $request)
 {
     $q = $request->get('q');
     $tag = str_slug($q);
     $authors = Author::where('name', 'ilike', "%{$q}%")->take(20)->get();
     $tags = Tag::where('name', 'ilike', "%{$tag}%")->take(20)->get();
     $query = \DB::table(\DB::raw("quotes, to_tsvector(quotes.content) target, to_tsquery('english', ?) query"))->select(['quotes.*', \DB::raw('ts_rank_cd(target, query) as rank')])->setBindings([str_replace(' ', '|', $q)]);
     $quotes = Quote::query()->setQuery($query)->published()->whereRaw(\DB::raw('target @@ query'))->orderBy('rank', 'desc')->paginate(50);
     foreach ($quotes as $quote) {
         $quote->content = $this->highlight($quote->content, $q);
     }
     $quotes->load(['author']);
     $quotes->appends(\Input::except('page'));
     return view('quote.index', compact('authors', 'tags', 'quotes', 'q'));
 }
コード例 #3
0
 /**
  * Display a listing of the resource.
  *
  * @param null|string $query
  *
  * @return \Quoterr\Http\Controllers\Response
  * @internal param \Illuminate\Http\Request $request
  *
  */
 public function index($query = null)
 {
     $quote = null;
     $meta = ['title' => 'Quoterr', 'description' => "Quoterr.me is an experience."];
     $api = '/api/quotes?random=1';
     if ($query !== null) {
         if (Uuid::isValid($query)) {
             $type = 'Press ‘space’ for next Quote';
             flash('Copy link from address bar to share this quote.');
             $quote = Quote::with('author')->whereUuid($query)->first();
             $meta['title'] = "A quote by {$quote->author->name} on Quoterr";
             $meta['description'] = "{$quote->content} Read awesome quotes on Quoterr.";
         } else {
             $author = Author::whereSlug($query)->first();
             if ($author) {
                 $type = "Showing quotes by {$author->name}";
                 $quote = $author->quotes()->published()->orderByRandom()->first();
                 $api = '/api/author?id=' . $query;
                 $meta['title'] = "Quotes by {$quote->author->name} on Quoterr";
                 $meta['description'] = "A fine quotation is a diamond in the hand of a man of wit, and a pebble in the hand of a fool. Read awesome quotes on Quoterr.";
             } else {
                 $tag = Tag::whereSlug($query)->first();
                 if ($tag) {
                     $type = "Quotes in {$tag->name} category";
                     $quote = $tag->quotes()->published()->orderByRandom()->first();
                     $api = '/api/tag?id=' . $query;
                 }
             }
         }
     }
     if (!$quote) {
         $type = 'Press ‘space’ for next Quote';
         $quote = Quote::with('author')->published()->orderByRandom()->first();
     }
     return view('welcome', compact('quote', 'api', 'type', 'meta'));
 }