diff --git a/app/Http/Controllers/PlaceController.php b/app/Http/Controllers/PlaceController.php index 6b7760fdc..bafa10dd5 100644 --- a/app/Http/Controllers/PlaceController.php +++ b/app/Http/Controllers/PlaceController.php @@ -2,33 +2,42 @@ namespace App\Http\Controllers; +use App\Place; +use App\Services\StatusService; +use App\Status; +use Cache; use Illuminate\Http\Request; -use App\{ - Place, - Status -}; class PlaceController extends Controller { - public function __construct() - { - $this->middleware('auth'); - } + const PLACES_CACHE_KEY = 'pf:places:sid-cache:by:placeid:'; + + public function __construct() + { + $this->middleware('auth'); + } public function show(Request $request, $id, $slug) { - $this->validate($request, [ - 'page' => 'sometimes|max:10' - ]); - - $place = Place::whereSlug($slug)->findOrFail($id); - $posts = Status::wherePlaceId($place->id) - ->whereNull('uri') - ->whereScope('public') - ->orderByDesc('created_at') - ->simplePaginate(10); - - return view('discover.places.show', compact('place', 'posts')); + $place = Place::whereSlug($slug)->findOrFail($id); + + $statusIds = Cache::remember(self::PLACES_CACHE_KEY.$place->id, now()->addMinutes(40), function () use ($place) { + return Status::select('id') + ->wherePlaceId($place->id) + ->whereScope('public') + ->whereIn('type', ['photo', 'photo:album', 'video']) + ->orderByDesc('id') + ->limit(50) + ->get(); + }); + + $posts = $statusIds->map(function ($item) { + return StatusService::get($item->id); + })->filter(function ($item) { + return $item && count($item['media_attachments'][0]); + })->take(18)->values(); + + return view('discover.places.show', compact('place', 'posts')); } public function directoryHome(Request $request) diff --git a/resources/views/discover/places/show.blade.php b/resources/views/discover/places/show.blade.php index b43ae681f..237b2c76b 100644 --- a/resources/views/discover/places/show.blade.php +++ b/resources/views/discover/places/show.blade.php @@ -2,47 +2,58 @@ @section('content')
- -
-
-
-
-
-
-
-
-
-
-

{{$place->name}}, {{$place->country}}

-

({{$place->lat}}, {{$place->long}})

-
-
-
-
-
-
-
- @if($posts->count() > 0) - @foreach($posts as $status) - - @endforeach - @else -
-

No results for this location

-
- @endif -
-
+
+
+
+
+
+
+
+
+
+
+

{{$place->name}}, {{$place->country}}

+

({{$place->lat}}, {{$place->long}})

+
+
+
+
+
+
+
+ @if($posts->count() > 0) + @foreach($posts as $status) + + @endforeach + @else +
+
+
+ +

No Posts Yet

+

There are no posts tagged at this location yet.

+ + Explore Other Places + +
+
+
+ @endif +
+
@endsection @push('scripts') -@endpush \ No newline at end of file +@endpush