Add sorting on home page and jumbotron

This commit is contained in:
dev 2021-08-11 17:47:43 -07:00
parent 99941bfd53
commit 87ef210e1f
4 changed files with 59 additions and 3 deletions

View File

@ -33,6 +33,33 @@ class MemeController extends Controller
SEOTools::setTitle('Home');
$data = [
'memes' => Meme::with(['user', 'tips'])->orderByDesc('created_at')->paginate(20),
'pt-0' => true,
];
return view('homepage', ['data' => $data]);
}
public function mostTipped()
{
SEOTools::setTitle('Most Tipped Memes');
$query = \DB::select("SELECT meme_id FROM `tips` GROUP BY meme_id ORDER BY SUM(AMOUNT) DESC");
$ids = array_column($query, 'meme_id');
$memes = Meme::with(['user', 'tips'])->whereIn('id', $ids)->orderByRaw("field(id,".implode(',',$ids).")")->paginate(20);
$data = [
'memes' => $memes,
'pt-0' => true,
];
return view('homepage', ['data' => $data]);
}
public function recentlyTipped()
{
SEOTools::setTitle('Recently Tipped Memes');
$query = \DB::select("SELECT meme_id FROM `tips` ORDER BY created_at DESC");
$ids = array_unique(array_column($query, 'meme_id'));
$memes = Meme::with(['user', 'tips'])->whereIn('id', $ids)->orderByRaw("field(id,".implode(',',$ids).")")->paginate(20);
$data = [
'memes' => $memes,
'pt-0' => true,
];
return view('homepage', ['data' => $data]);
}

View File

@ -2,8 +2,28 @@
@section('content')
<div class="container-fluid">
<div class="row">
<div class="col-12 px-0">
<div class="jumbotron jumbotron-fluid mt-0 bg-primary text-light text-center">
<div class="container">
<h1 class="display-4">XMR Memes</h1>
<p class="lead">Get tipped Monero (XMR) for making memes about Monero.</p>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-12 mb-4">
<div class="btn-group w-100" role="group" aria-label="Basic example">
<a role="button" href="{{ url('') }}" class="btn btn-primary text-light {{ Request::routeIs('homepage') ? 'active' : '' }}">Latest</a>
<a role="button" href="{{ url('recently-tipped') }}" class="btn btn-primary text-light {{ Request::routeIs('recently-tipped') ? 'active' : '' }}">Recently Tipped</a>
<a role="button" href="{{ url('most-tipped') }}" class="btn btn-primary text-light {{ Request::routeIs('most-tipped') ? 'active' : '' }}">Most Tipped</a>
</div>
</div>
<div class="col-md-12">
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-4 grid-memes">
@foreach ($data['memes'] as $meme)

View File

@ -115,9 +115,16 @@
</div>
</div>
</nav>
<main class="py-4">
@yield('content')
</main>
@if (isset($data['pt-0']))
<main class="pb-4">
@yield('content')
</main>
@else
<main class="py-4">
@yield('content')
</main>
@endif
<footer class="container-fluid py-5 bg-light shadow-lg text-center">
<div class="row">

View File

@ -16,6 +16,8 @@ use Illuminate\Support\Facades\Route;
Auth::routes();
Route::get('/', [App\Http\Controllers\MemeController::class, 'index'])->name('homepage');
Route::get('/most-tipped', [App\Http\Controllers\MemeController::class, 'mostTipped'])->name('most-tipped');
Route::get('/recently-tipped', [App\Http\Controllers\MemeController::class, 'recentlyTipped'])->name('recently-tipped');
Route::get('/about', [App\Http\Controllers\AboutController::class, 'index'])->name('about');
Route::get('/contact', [App\Http\Controllers\ContactController::class, 'index'])->name('contact');
Route::get('meme/{id}', [App\Http\Controllers\MemeController::class, 'show'])->name('meme');