fix middleware to redirect
This commit is contained in:
parent
b28d546690
commit
f2562b10ee
5 changed files with 20 additions and 16 deletions
|
|
@ -3,8 +3,7 @@
|
|||
namespace App\Http\Controllers\Club;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
class GoldenCrushController extends Controller
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,17 +11,22 @@ class RedirectToGoldenIfVoteOpen
|
|||
{
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
if ($request->routeIs('club.golden-crush')) {
|
||||
return $next($request);
|
||||
$startAt = config('vote.start_at');
|
||||
$endAt = config('vote.end_at');
|
||||
|
||||
if (! $startAt || ! $endAt) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
if (auth('club')->check()) {
|
||||
$startAt = Carbon::parse(config('vote.start_at'));
|
||||
$endAt = Carbon::parse(config('vote.end_at'));
|
||||
$isOpen = now()->between(
|
||||
Carbon::parse($startAt),
|
||||
Carbon::parse($endAt)
|
||||
);
|
||||
|
||||
if (now()->between($startAt, $endAt)) {
|
||||
return redirect()->route('club.golden-crush');
|
||||
}
|
||||
if (! $isOpen) {
|
||||
return redirect()
|
||||
->route('club.home')
|
||||
->with('error', 'La période d’accès à cette page est terminée ou non commencée.');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@
|
|||
|
||||
<div class="idea-wave mx-auto mb-4 mb-md-5"></div>
|
||||
|
||||
<a href="#" class="idea-btn">
|
||||
<a href="{{ route('club.golden-crush') }}" class="idea-btn">
|
||||
JE PARTICIPE <i class="fa-solid fa-arrow-right"></i>
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@
|
|||
{{-- Boutton --}}
|
||||
<div class="row pt-2 pt-md-3">
|
||||
<div class="col-12 d-flex justify-content-center">
|
||||
<a href="#participer" class="btn-participe">
|
||||
<a href="{{ route('club.golden-crush') }}" class="btn-participe">
|
||||
<span>JE PARTICIPE <i class="fa-solid fa-arrow-right"></i></span>
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -43,9 +43,7 @@ Route::name('club.')->prefix('club')->group(function () {
|
|||
}
|
||||
|
||||
// * STATIC PAGES
|
||||
Route::get('/', [HomeController::class, 'index'])
|
||||
->middleware(['vote.redirect'])
|
||||
->name('home.show');
|
||||
Route::get('/', [HomeController::class, 'index'])->name('home.show');
|
||||
|
||||
Route::middleware(['auth:club', EnsureEmailIsVerified::class])->group(function () {
|
||||
Route::get('mon-compte', [CustomerController::class, 'index'])->name('customers.index');
|
||||
|
|
@ -135,7 +133,9 @@ Route::name('club.')->prefix('club')->group(function () {
|
|||
Route::post('reductions/print', [DiscountController::class, 'fetchBrPdf'])->name('discounts.print');
|
||||
|
||||
// * GOLDEN CRUSH
|
||||
Route::get('/golden-crush', [GoldenCrushController::class, 'index'])->name('golden-crush');
|
||||
Route::get('/golden-crush', [GoldenCrushController::class, 'index'])
|
||||
->middleware(['vote.redirect'])
|
||||
->name('golden-crush');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue