1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace App\Http\Controllers;
- use App\Place;
- use App\Services\StatusService;
- use App\Status;
- use Cache;
- use Illuminate\Http\Request;
- class PlaceController extends Controller
- {
- const PLACES_CACHE_KEY = 'pf:places:sid-cache:by:placeid:';
- public function __construct()
- {
- $this->middleware('auth');
- }
- public function show(Request $request, $id, $slug)
- {
- $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)
- {
- $places = Place::select('country')
- ->distinct('country')
- ->simplePaginate(48);
- return view('discover.places.directory.home', compact('places'));
- }
- public function directoryCities(Request $request, $country)
- {
- $country = ucfirst(urldecode($country));
- $places = Place::whereCountry($country)
- ->orderBy('name', 'asc')
- ->distinct('name')
- ->simplePaginate(48);
- return view('discover.places.directory.cities', compact('places'));
- }
- }
|