Update PlaceController, fix show method

pull/6001/head
Daniel Supernault 6 months ago
parent 5539dd0e1b
commit f81a4acdc6
No known key found for this signature in database
GPG Key ID: 23740873EE6F76A1

@ -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)

@ -2,47 +2,58 @@
@section('content')
<div class="container">
<div class="profile-header row my-5">
<div class="col-12 col-md-2">
<div class="profile-avatar">
<div class="bg-pixelfed mb-3 d-flex align-items-center justify-content-center display-4 font-weight-bold text-white" style="width: 132px; height: 132px; border-radius: 100%"><i class="fas fa-map-pin"></i></div>
</div>
</div>
<div class="col-12 col-md-9 d-flex align-items-center">
<div class="profile-details">
<div class="username-bar pb-2 d-flex align-items-center">
<div class="ml-4">
<p class="h3 font-weight-lighter">{{$place->name}}, {{$place->country}}</p>
<p class="small text-muted">({{$place->lat}}, {{$place->long}})</p>
</div>
</div>
</div>
</div>
</div>
<div class="tag-timeline">
<div class="row">
@if($posts->count() > 0)
@foreach($posts as $status)
<div class="col-4 p-0 p-sm-2 p-md-3">
<a class="card info-overlay card-md-border-0" href="{{$status->url()}}">
<div class="square {{$status->firstMedia()->filter_class}}">
<div class="square-content" style="background-image: url('{{$status->thumb()}}')"></div>
</div>
</a>
</div>
@endforeach
@else
<div class="col-12 bg-white p-5 border">
<p class="lead text-center text-dark mb-0">No results for this location</p>
</div>
@endif
</div>
</div>
<div class="profile-header row mt-4">
<div class="col-12 col-md-2">
<div class="profile-avatar">
<div class="bg-pixelfed mb-3 d-flex align-items-center justify-content-center display-4 font-weight-bold text-white" style="width: 132px; height: 132px; border-radius: 100%"><i class="fal fa-map-pin"></i></div>
</div>
</div>
<div class="col-12 col-md-9 d-flex align-items-center">
<div class="profile-details">
<div class="username-bar pb-2 d-flex align-items-center">
<div class="ml-4">
<p class="h3 font-weight-lighter">{{$place->name}}, {{$place->country}}</p>
<p class="small text-muted">({{$place->lat}}, {{$place->long}})</p>
</div>
</div>
</div>
</div>
</div>
<div class="tag-timeline">
<div class="row">
@if($posts->count() > 0)
@foreach($posts as $status)
<div class="col-4 p-1 p-lg-2">
<a class="card info-overlay card-md-border-0" href="{{$status['url']}}">
<picture class="square bg-muted">
@if(!Str::endsWith($status['media_attachments'][0]['preview_url'], 'no-preview.png'))
<source class="square-content" srcset="{{ $status['media_attachments'][0]['preview_url'] }}" />
@endif
<img class="square-content" src="{{ $status['media_attachments'][0]['url'] }}" alt="{{ $status['media_attachments'][0]['description'] ?? 'Photo was not tagged with any alt text' }}" onerror="this.src='/storage/no-preview.png';this.onerror=null;" />
</picture>
</a>
</div>
@endforeach
@else
<div class="col-12">
<div class="card shadow-sm border text-center py-5">
<div class="card-body">
<i class="far fa-images fa-4x text-muted mb-3"></i>
<h4>No Posts Yet</h4>
<p class="text-muted">There are no posts tagged at this location yet.</p>
<a href="/discover/places" class="btn btn-primary mt-2">
Explore Other Places
</a>
</div>
</div>
</div>
@endif
</div>
</div>
</div>
@endsection
@push('scripts')
<script type="text/javascript" src="{{ mix('js/compose.js') }}"></script>
<script type="text/javascript">App.boot();</script>
@endpush
@endpush

Loading…
Cancel
Save