generated from liutk/owl-admin-base
62 lines
1.9 KiB
PHP
62 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register any application services.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
$this->app->singleton('admin.menu', \App\Admin\Menu::class);
|
|
}
|
|
|
|
/**
|
|
* Bootstrap any application services.
|
|
*/
|
|
public function boot()
|
|
{
|
|
JsonResource::withoutWrapping();
|
|
|
|
$this->definePolymorphicTypes();
|
|
|
|
Validator::extend('phone', function ($attribute, $value, $parameters, $validator) {
|
|
return preg_match('/^1[\d]{10}$/', $value);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 自定义多态类型
|
|
*/
|
|
protected function definePolymorphicTypes(): void
|
|
{
|
|
Relation::enforceMorphMap(
|
|
collect([
|
|
\App\Models\AdminUser::class,
|
|
\App\Models\Employee::class,
|
|
\App\Models\EmployeeSignRepair::class,
|
|
\App\Models\HolidayApply::class,
|
|
\App\Models\OvertimeApply::class,
|
|
\App\Models\OfficalBusiness::class,
|
|
\App\Models\Ledger::class,
|
|
\App\Models\PlanHygiene::class,
|
|
\App\Models\PlanLedger::class,
|
|
\App\Models\PlanPerformance::class,
|
|
\App\Models\Reimbursement::class,
|
|
\App\Models\StoreMasterCommission::class,
|
|
\App\Models\TaskHygiene::class,
|
|
\App\Models\TaskLedger::class,
|
|
\App\Models\TaskPerformance::class,
|
|
\App\Models\EmployeePromotion::class,
|
|
\App\Models\Agreement::class,
|
|
])->mapWithKeys(fn ($model) => [(new $model)->getTable() => $model])->all()
|
|
);
|
|
}
|
|
}
|