Beispiel #1
0
 public function searchAriticleByTitle(Request $request)
 {
     $title = $request->input('title');
     Session::flash('search_title', $title);
     $articles = Article::whereRaw('title like ?', ["%{$title}%"])->orderBy('created_at', 'desc')->paginate();
     return view('welcome')->with(['articles' => $articles, 'search_data' => ['title' => $title]]);
 }
Beispiel #2
0
 /**
  * rss
  */
 public function feed()
 {
     $rss = \RSS::make();
     Log::info("开始构建RSS XML.");
     if (Cache::has('self:rss')) {
         Log::info("发现缓存的RSS XMLDOCUMENT。");
         $rss = Cache::get("self:rss");
         // make channel.
     } else {
         Log::info("没有发现缓存中存在RSS XMLDOCUMENT。开始构建。");
         $rss->channel(['title' => 'LuBlog', 'description' => '蝼蚁虽小,也有梦想。', 'link' => url('/')])->withImage(['url' => asset('/images/avatar.jpg'), 'title' => '头像', 'link' => url('/')]);
         $articles = Article::orderBy('created_at', 'desc')->take(20)->get();
         // gen posts data ......
         foreach ($articles as $article) {
             $rss->item(['title' => $article->title, 'description|cdata' => $article->description, 'link' => url('/article/' . $article->id)]);
         }
         $expries_at = Carbon::now()->addMinutes(30);
         Cache::put('self:rss', $rss, $expries_at);
     }
     // If you want to save the rss data to file.
     // $rss->save('rss.xml');
     // Or just make a response to the http request.
     return \Response::make($rss->render(), 200, ['Content-Type' => 'text/xml']);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param int $id            
  * @return Response
  */
 public function destroy($id)
 {
     if (Article::destroy($id)) {
         $this->clear_articels_cache();
         $message = "删除文章成功";
     } else {
         $message = "删除文章失败";
     }
     return redirect('/admin/article')->with('message', $message);
 }