You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.1 KiB

  1. <?php
  2. namespace App\Http\Controllers\Wap;
  3. use Illuminate\Support\Facades\DB;
  4. class PageController extends BaseController
  5. {
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. }
  10. //单页面
  11. public function detail($id)
  12. {
  13. $data = [];
  14. if (!empty($id) && preg_match('/[a-z0-9]+/', $id)) {
  15. $map['filename'] = $id;
  16. if (cache("pageid$id")) {
  17. $post = cache("pageid$id");
  18. } else {
  19. $post = object_to_array(DB::table('page')->where($map)->first(), 1);
  20. cache("pageid$id", $post, 2592000);
  21. cache(["pageid$id" => $post], \Carbon\Carbon::now()->addMinutes(2592000));
  22. }
  23. if (!$post) {
  24. return redirect()->route('page404');
  25. }
  26. $data['post'] = $post;
  27. } else {
  28. return redirect()->route('page404');
  29. }
  30. $data['posts'] = object_to_array(DB::table('page')->orderBy(\DB::raw('rand()'))->take(5)->get());
  31. return view('wap.page.detail', $data);
  32. }
  33. }