feat: refactor code and improve readability

This commit is contained in:
Rico van Zelst
2025-03-04 12:50:19 +01:00
parent efc263e257
commit 68d18311b4
8 changed files with 25 additions and 34 deletions

View File

@@ -20,12 +20,15 @@ class ContactSubmissionController extends Controller
$descriptionContent = "**Name**: {$contactSubmission->name}\n\n**Email**: {$contactSubmission->email}\n\n**Category**: {$contactSubmission->category->humanReadable()}\n\n**Subject**: {$contactSubmission->subject}\n\n**Message**: {$contactSubmission->message}";
if ($contactSubmission->discord) {
$descriptionContent .= "\n\n\n**Discord**: {$contactSubmission->discord}";
$descriptionContent .= '
**Discord**: ' . $contactSubmission->discord;
}
DiscordAlert::message("There is a new contact submission from {$contactSubmission->name} ({$contactSubmission->email}).", [
DiscordAlert::message(sprintf('There is a new contact submission from %s (%s).', $contactSubmission->name, $contactSubmission->email), [
[
'title' => "{$contactSubmission->category->humanReadable()} - {$contactSubmission->subject}",
'title' => sprintf('%s - %s', $contactSubmission->category->humanReadable(), $contactSubmission->subject),
'description' => $descriptionContent,
'color' => '#ff8a4c',
],

View File

@@ -10,9 +10,7 @@ class PostsController extends Controller
{
public function index()
{
$posts = Sheets::all()->filter(function ($post) {
return ! $post->hidden;
})->sortByDesc('date');
$posts = Sheets::all()->filter(fn($post) => ! $post->hidden)->sortByDesc('date');
$paginatedPosts = Paginate::collection($posts, 6);
return view('posts.index', [

View File

@@ -27,12 +27,12 @@ class SaleController extends Controller
return $response;
});
} catch (\Exception $e) {
if ($e->getMessage() === 'Trying to access array offset on value of type null') {
} catch (\Exception $exception) {
if ($exception->getMessage() === 'Trying to access array offset on value of type null') {
logger()->error('LMI has broken');
abort(503, 'Sorry, the Sale Rotation is currently under maintenance. Please try again later.');
} else {
logger()->error('An error occurred while trying to fetch the Sale Rotation', ['error' => $e->getMessage()]);
logger()->error('An error occurred while trying to fetch the Sale Rotation', ['error' => $exception->getMessage()]);
abort(500, 'Sorry, an error occurred while trying to fetch the Sale Rotation. Please try again later.');
}
}