Skip to content

Commit

Permalink
fix(Helper.php): fix for redeclare messages
Browse files Browse the repository at this point in the history
  • Loading branch information
daveroverts committed Feb 13, 2022
1 parent a4e0350 commit 85711c8
Showing 1 changed file with 40 additions and 32 deletions.
72 changes: 40 additions & 32 deletions app/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,51 @@
use App\Models\Event;
use Illuminate\Support\Collection;

function flashMessage($type, $title, $text): void
{
session()->flash('type', $type);
session()->flash('title', $title);
session()->flash('text', $text);
}

function nextEvent($homepage = false): Event
{
return nextEvents(true, false, $homepage);
}

function nextEvents($one = false, $showAll = false, $homepage = false, $withRelations = []): Event|Collection
{
$events = Event::where('endEvent', '>', now())
->orderBy('startEvent');
if (!$showAll) {
$events = $events->where('is_online', true);
}
if ($homepage) {
$events = $events->where('show_on_homepage', true);
if (!function_exists('flashMessage')) {
function flashMessage($type, $title, $text): void
{
session()->flash('type', $type);
session()->flash('title', $title);
session()->flash('text', $text);
}
}

if (!empty($withRelations)) {
$events = $events->with($withRelations);
if (!function_exists('nextEvent')) {
function nextEvent($homepage = false): Event
{
return nextEvents(true, false, $homepage);
}
}

if ($one) {
$events = $events->first();
} else {
$events = $events->get();
if (!function_exists('nextEvents')) {
function nextEvents($one = false, $showAll = false, $homepage = false, $withRelations = []): Event|Collection
{
$events = Event::where('endEvent', '>', now())
->orderBy('startEvent');
if (!$showAll) {
$events = $events->where('is_online', true);
}
if ($homepage) {
$events = $events->where('show_on_homepage', true);
}

if (!empty($withRelations)) {
$events = $events->with($withRelations);
}

if ($one) {
$events = $events->first();
} else {
$events = $events->get();
}

return $events;
}

return $events;
}

function nextEventsForFaq(): Collection
{
return nextEvents(false, false, false, 'faqs');
if (!function_exists('nextEventsForFaq')) {
function nextEventsForFaq(): Collection
{
return nextEvents(false, false, false, 'faqs');
}
}

0 comments on commit 85711c8

Please sign in to comment.