😁2.6.2.2 Create Folder Helpers & include files (ok)

C:\xampp82\htdocs\lva2\app\Helpers\app.php

<?php
declare(strict_types=1);
namespace App\Helpers;
use Rawilk\FormComponents\Support\TimeZoneRegionEnum;
function timezoneSubsets(): array
{
  return [
    TimeZoneRegionEnum::General->value,
    TimeZoneRegionEnum::America->value,
  ];
}

C:\xampp82\htdocs\lva2\app\Helpers\helpers.php

<?php
declare(strict_types=1);
use Symfony\Component\Finder\Finder;
$files = Finder::create()
  ->files()
  ->in(__DIR__)
  ->depth(0)
  ->name('*.php');
foreach ($files as $file) {
  require_once $file;
}

C:\xampp82\htdocs\lva2\app\Helpers\routes.php

<?php
declare(strict_types=1);
namespace App\Helpers;
function defaultLoginRedirect(): string
{
  return auth()->user()?->can('viewAdminPanel')
    ? route('admin.dashboard')
    : route('profile.show');
}
function homeRoute(): string
{
  if (auth()->check() && auth()->user()->isSuperAdmin()) {
    return route('admin.dashboard');
  }
  return '/';
}

Quan trọng nhất là:

"autoload": {
    "psr-4": {
      "App\\": "app/",
      "Database\\Factories\\": "database/factories/",
      "Database\\Seeders\\": "database/seeders/"
    },
    "files": [
      "app/Helpers/helpers.php"
    ]
  },

Last updated