/
FoundationServiceProvider.php
68 lines (60 loc) · 1.55 KB
/
FoundationServiceProvider.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
<?php
namespace Illuminate\Foundation\Providers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\AggregateServiceProvider;
class FoundationServiceProvider extends AggregateServiceProvider
{
/**
* The provider class names.
*
* @var array
*/
protected $providers = [
FormRequestServiceProvider::class,
];
/**
* Boot the service provider.
*/
public function boot()
{
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__.'/../Exceptions/views' => $this->app->resourcePath('views/errors/'),
], 'laravel-errors');
}
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
parent::register();
$this->registerRequestValidation();
$this->registerRequestSignatureValidation();
}
/**
* Register the "validate" macro on the request.
*
* @return void
*/
public function registerRequestValidation()
{
Request::macro('validate', function (array $rules, ...$params) {
return validator()->validate($this->all(), $rules, ...$params);
});
}
/**
* Register the "hasValidSignature" macro on the request.
*
* @return void
*/
public function registerRequestSignatureValidation()
{
Request::macro('hasValidSignature', function ($absolute = true) {
return URL::hasValidSignature($this, $absolute);
});
}
}