|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Webfactor\Laravel\Backpack\NestedModels; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Schema\Blueprint; |
|
6
|
|
|
use Illuminate\Routing\Router; |
|
7
|
|
|
use Illuminate\Support\ServiceProvider; |
|
8
|
|
|
|
|
9
|
|
|
class NestedModelsServiceProvider extends ServiceProvider |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Perform post-registration booting of services. |
|
13
|
|
|
* |
|
14
|
|
|
* @return void |
|
15
|
|
|
*/ |
|
16
|
|
|
public function boot() |
|
17
|
|
|
{ |
|
18
|
|
|
// LOAD THE VIEWS |
|
19
|
|
|
$this->loadViewsFrom(resource_path('views/vendor/webfactor/nestedmodels'), 'nestedmodels'); |
|
20
|
|
|
$this->loadViewsFrom(realpath(__DIR__.'/../views'), 'nestedmodels'); |
|
21
|
|
|
|
|
22
|
|
|
$this->macros(); |
|
23
|
|
|
|
|
24
|
|
|
$this->publish(); |
|
25
|
|
|
|
|
26
|
|
|
// AUTO PUBLISH |
|
27
|
|
|
if (\App::environment('local')) { |
|
28
|
|
|
if ($this->shouldAutoPublishPublic()) { |
|
29
|
|
|
\Artisan::call('vendor:publish', [ |
|
30
|
|
|
'--provider' => 'Backpack\CRUD\CrudServiceProvider', |
|
31
|
|
|
'--tag' => 'public', |
|
32
|
|
|
]); |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Register any package services. |
|
39
|
|
|
* |
|
40
|
|
|
* @return void |
|
41
|
|
|
*/ |
|
42
|
|
|
public function register() |
|
43
|
|
|
{ |
|
44
|
|
|
// |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function publish() |
|
48
|
|
|
{ |
|
49
|
|
|
$this->publishes([__DIR__.'/../views' => resource_path('views/vendor/webfactor/nestedmodels')], 'views'); |
|
50
|
|
|
|
|
51
|
|
|
$this->publishes([__DIR__.'/../public' => public_path('vendor/webfactor/nestedmodels')], 'public'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
public function macros() |
|
56
|
|
|
{ |
|
57
|
|
|
Blueprint::macro('tree', function () { |
|
58
|
|
|
$this->unsignedInteger('parent_id')->nullable()->index(); |
|
|
|
|
|
|
59
|
|
|
$this->unsignedInteger('lft')->default(0)->index(); |
|
|
|
|
|
|
60
|
|
|
$this->unsignedInteger('rgt')->default(0)->index(); |
|
|
|
|
|
|
61
|
|
|
$this->unsignedInteger('depth')->default(0); |
|
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
$this->foreign('parent_id')->references('id')->on($this->table) |
|
|
|
|
|
|
64
|
|
|
->onUpdate('cascade')->onDelete('cascade'); |
|
65
|
|
|
}); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Checks to see if we should automatically publish |
|
70
|
|
|
* vendor files from the public tag. |
|
71
|
|
|
* |
|
72
|
|
|
* @return bool |
|
73
|
|
|
*/ |
|
74
|
|
|
private function shouldAutoPublishPublic() |
|
75
|
|
|
{ |
|
76
|
|
|
$crudPubPath = public_path('vendor/webfactor/nestedmodels'); |
|
77
|
|
|
|
|
78
|
|
|
if (! is_dir($crudPubPath)) { |
|
|
|
|
|
|
79
|
|
|
return true; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return false; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.