|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Providers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
|
6
|
|
|
use Illuminate\Support\Facades\Schema; |
|
7
|
|
|
use Illuminate\Support\Facades\Validator; |
|
8
|
|
|
|
|
9
|
|
|
class AppServiceProvider extends ServiceProvider |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Bootstrap any application services. |
|
13
|
|
|
* |
|
14
|
|
|
* @return void |
|
15
|
|
|
*/ |
|
16
|
5 |
|
public function boot() |
|
17
|
|
|
{ |
|
18
|
|
|
// Fixes incompatibility with MySQL < 5.7.7 |
|
19
|
5 |
|
Schema::defaultStringLength(191); |
|
20
|
|
|
|
|
21
|
|
|
// Create {{ $view_name }} provider in blade templates |
|
22
|
5 |
|
view()->composer('*', function($view) { |
|
|
|
|
|
|
23
|
|
|
$view_name = str_replace('.', '-', $view->getName()); |
|
24
|
|
|
view()->share('view_name', $view_name); |
|
|
|
|
|
|
25
|
5 |
|
}); |
|
26
|
|
|
|
|
27
|
5 |
|
Validator::extend('phone', function($attribute, $value, $parameters, $validator) { |
|
|
|
|
|
|
28
|
|
|
return preg_match('%^(?:(?:\(?(?:00|\+)([1-4]\d\d|[1-9]\d?)\)?)?[\-\.\ \\\/]?)?((?:\(?\d{1,}\)?[\-\.\ \\\/]?){0,})(?:[\-\.\ \\\/]?(?:#|ext\.?|extension|x)[\-\.\ \\\/]?(\d+))?$%i', $value) && strlen($value) >= 10; |
|
29
|
5 |
|
}); |
|
30
|
|
|
|
|
31
|
5 |
|
Validator::replacer('phone', function($message, $attribute, $rule, $parameters) { |
|
|
|
|
|
|
32
|
|
|
return str_replace(':attribute', $attribute, ':attribute is invalid phone number'); |
|
33
|
5 |
|
}); |
|
34
|
|
|
|
|
35
|
|
|
//Validator rule for names |
|
36
|
5 |
|
Validator::extend('name', function($attribute, $value, $parameters, $validator) { |
|
|
|
|
|
|
37
|
|
|
return preg_match('#(^[a-zA-Z0-9])([\w\-\.\' ]*)([\w\-\.\']$)#', $value); |
|
38
|
5 |
|
}); |
|
39
|
|
|
|
|
40
|
5 |
|
Validator::replacer('name', function($message, $attribute, $rule, $parameters) { |
|
|
|
|
|
|
41
|
|
|
return str_replace(':attribute', $attribute, ':attribute is invalid you can only use letters, numbers, underscores, dashes, spaces, periods and it must start with a letter or number'); |
|
42
|
5 |
|
}); |
|
43
|
5 |
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Register any application services. |
|
47
|
|
|
* |
|
48
|
|
|
* @return void |
|
49
|
|
|
*/ |
|
50
|
5 |
|
public function register() |
|
51
|
|
|
{ |
|
52
|
|
|
// |
|
53
|
5 |
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: