2
2
3
3
namespace App \Providers ;
4
4
5
+ use App \Models \Post ;
6
+ use App \Models \Project ;
7
+ use App \Models \Task ;
5
8
use App \Services \ActivityService ;
6
9
use Carbon \Carbon ;
7
- use Illuminate \Support \Facades \File ;
8
10
use Illuminate \Support \ServiceProvider ;
9
- use Statamic \Entries \Entry ;
10
- use Statamic \Facades \Collection ;
11
11
12
12
class AppServiceProvider extends ServiceProvider
13
13
{
@@ -19,7 +19,7 @@ public function register(): void
19
19
public function boot (): void
20
20
{
21
21
$ this ->bootCarbon ();
22
- $ this ->bootCollections ();
22
+ $ this ->bootModels ();
23
23
}
24
24
25
25
protected function bootCarbon (): void
@@ -48,72 +48,10 @@ protected function bootCarbon(): void
48
48
});
49
49
}
50
50
51
- protected function bootCollections (): void
51
+ protected function bootModels (): void
52
52
{
53
- Collection::computed ('posts ' , 'summary ' , function (Entry $ post ) {
54
- if (! isset ($ post ->content ) || ! is_string ($ post ->content )) {
55
- return null ;
56
- }
57
-
58
- $ summary = substr ($ post ->content , 0 , strpos ($ post ->content , '<h2 ' ) ?: 0 );
59
- $ summary = preg_replace ('/<a(\s|>)[^>]*>(.*?)<\/a>/ ' , '$2 ' , $ summary ) ?: '' ;
60
- $ summary = preg_replace ('/<img[^>]*>/ ' , '' , $ summary );
61
-
62
- return $ summary ;
63
- });
64
-
65
- Collection::computed ('posts ' , 'duration ' , function (Entry $ post ) {
66
- if (! isset ($ post ->content ) || ! is_string ($ post ->content )) {
67
- return null ;
68
- }
69
-
70
- $ words = str_word_count (strip_tags ($ post ->content ));
71
-
72
- return round ($ words / 200 );
73
- });
74
-
75
- Collection::computed ('posts ' , 'landmarks ' , function (Entry $ post ) {
76
- if (! isset ($ post ->content ) || ! is_string ($ post ->content )) {
77
- return null ;
78
- }
79
-
80
- return parse_landmarks ($ post ->content );
81
- });
82
-
83
- Collection::computed ('projects ' , 'stateClasses ' , function (Entry $ project ) {
84
- switch ($ project ->value ('state ' )) {
85
- case 'live ' :
86
- return 'bg-jade-lighter text-jade-darker ' ;
87
- case 'archived ' :
88
- case 'experimental ' :
89
- return 'bg-yellow-lighter text-yellow-darker ' ;
90
- default :
91
- return 'bg-blue-lighter text-blue-darker ' ;
92
- }
93
- });
94
-
95
- Collection::computed ('projects ' , 'images ' , function (Entry $ project ) {
96
- $ id = $ project ->id ();
97
-
98
- if (! is_string ($ id )) {
99
- return [];
100
- }
101
-
102
- $ project = substr ($ id , 0 , strlen ($ id ) - 8 );
103
- $ imagesPath = "img/projects/ {$ project }/images " ;
104
-
105
- return collect (File::files (public_path ($ imagesPath )))
106
- ->map (function ($ file , $ index ) use ($ imagesPath ) {
107
- $ filename = $ file ->getFilename ();
108
- $ number = $ index + 1 ;
109
-
110
- return [
111
- 'url ' => "/ {$ imagesPath }/ {$ filename }" ,
112
- 'description ' => "Project image ( {$ number }) " ,
113
- ];
114
- })
115
- ->sortBy ('url ' )
116
- ->toArray ();
117
- });
53
+ Post::boot ();
54
+ Task::boot ();
55
+ Project::boot ();
118
56
}
119
57
}
0 commit comments