-
Notifications
You must be signed in to change notification settings - Fork 1
/
AppServiceProvider.php
73 lines (62 loc) · 1.82 KB
/
AppServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
namespace App\Providers;
use Blade;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* The path to the "home" route for your application.
*
* This is used by Laravel authentication to redirect users after login.
*
* @var string
*/
public const HOME = '/dashboard';
/**
* Register any application services.
*/
public function register(): void
{
//
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
Model::preventLazyLoading(! app()->isProduction());
if (app()->isProduction()) {
URL::forceScheme('https');
}
/**
* Blade directive that will display any Markdown text as formatted HTML.
*
* @param string $markdown
* @return string php of the blade directive
*/
Blade::directive('markdown', function ($markdown) {
if ($markdown) {
return '
<?php
$converter = new \League\CommonMark\CommonMarkConverter([\'html_input\' => \'escape\', \'allow_unsafe_links\' => false]);
echo $converter->convertToHtml((string) ' . $markdown . ');
?>
';
}
return '<?php ob_start(); ?>';
});
$this->bootRoute();
}
public function bootRoute(): void
{
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
});
}
}