45 lines
829 B
PHP
45 lines
829 B
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register()
|
|
{
|
|
$this->registerRequestRealIp();
|
|
}
|
|
|
|
/**
|
|
* Bootstrap any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot()
|
|
{
|
|
Relation::enforceMorphMap([
|
|
'user' => \App\Models\User::class,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 在请求上注册 realIp 宏
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function registerRequestRealIp()
|
|
{
|
|
Request::macro('realIp', function () {
|
|
return $this->ip();
|
|
});
|
|
}
|
|
}
|