laravel-learn-bbs/app/Providers/AppServiceProvider.php

54 lines
1.3 KiB
PHP
Raw Normal View History

2017-12-24 14:17:18 +00:00
<?php
namespace App\Providers;
2018-06-02 13:48:16 +00:00
use App\Models\Link;
2018-01-15 15:59:30 +00:00
use App\Models\Reply;
2018-01-01 12:18:33 +00:00
use App\Models\Topic;
2018-06-02 13:48:16 +00:00
use App\Observers\LinkObserver;
2018-01-15 15:59:30 +00:00
use App\Observers\ReplyObserver;
2018-01-01 12:18:33 +00:00
use App\Observers\TopicObserver;
2017-12-30 20:23:09 +00:00
use Carbon\Carbon;
2018-06-10 10:35:53 +00:00
use Dingo\Api\Facade\API;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
2017-12-24 14:17:18 +00:00
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
2017-12-30 20:23:09 +00:00
Carbon::setLocale('zh');
2018-01-01 12:18:33 +00:00
Topic::observe(new TopicObserver());
2018-01-15 15:59:30 +00:00
Reply::observe(new ReplyObserver());
2018-06-02 13:48:16 +00:00
Link::observe(new LinkObserver());
2017-12-24 14:17:18 +00:00
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
2018-01-01 04:38:52 +00:00
if ($this->app->environment() !== 'production') {
$this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
}
2018-02-12 13:39:52 +00:00
if (app()->isLocal()) {
$this->app->register(\VIACreative\SudoSu\ServiceProvider::class);
}
2018-06-10 10:35:53 +00:00
API::error(function (ModelNotFoundException $exception) {
abort(404);
});
API::error(function (AuthorizationException $exception) {
abort(403, $exception->getMessage());
});
2017-12-24 14:17:18 +00:00
}
}