generator-folklore 3.0.5 → 3.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. package/lib/generators/intl/index.js +93 -0
  2. package/lib/generators/laravel-mediatheque/index.js +133 -0
  3. package/lib/generators/laravel-mediatheque/templates/app/Models/Media.php +9 -0
  4. package/lib/generators/laravel-mediatheque/templates/app/Models/MediaFile.php +9 -0
  5. package/lib/generators/laravel-panneau/index.js +49 -28
  6. package/lib/generators/laravel-panneau/templates/app/Contracts/Repositories/Pages.php +19 -0
  7. package/lib/generators/laravel-panneau/templates/app/Contracts/Resources/Blocks/Text.php +10 -0
  8. package/lib/generators/laravel-panneau/templates/app/Contracts/Resources/Page.php +10 -0
  9. package/lib/generators/laravel-panneau/templates/app/Contracts/Resources/Pages/Home.php +9 -0
  10. package/lib/generators/laravel-panneau/templates/app/Http/Resources/BlockResource.php +37 -0
  11. package/lib/generators/laravel-panneau/templates/app/Http/Resources/BlocksCollection.php +8 -0
  12. package/lib/generators/laravel-panneau/templates/app/Http/Resources/PageResource.php +47 -0
  13. package/lib/generators/laravel-panneau/templates/app/Http/Resources/PagesCollection.php +10 -0
  14. package/lib/generators/laravel-panneau/templates/app/Models/Block.php +3 -13
  15. package/lib/generators/laravel-panneau/templates/app/Models/Page.php +3 -60
  16. package/lib/generators/laravel-panneau/templates/app/Panneau/Composers/AppComposer.php +50 -0
  17. package/lib/generators/laravel-panneau/templates/app/Panneau/Fields/Block.php +22 -0
  18. package/lib/generators/laravel-panneau/templates/app/Panneau/Fields/Blocks.php +87 -0
  19. package/lib/generators/laravel-panneau/templates/app/Panneau/Fields/Page.php +51 -0
  20. package/lib/generators/laravel-panneau/templates/app/Panneau/Fields/PageSlug.php +34 -0
  21. package/lib/generators/laravel-panneau/templates/app/Panneau/Fields/PageSlugLocalized.php +18 -0
  22. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Controllers/AccountController.php +41 -0
  23. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Controllers/Controller.php +19 -0
  24. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Controllers/HomeController.php +16 -0
  25. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Controllers/PagesController.php +24 -0
  26. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Controllers/UploadController.php +27 -0
  27. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Controllers/UsersController.php +32 -0
  28. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Requests/AccountUpdateRequest.php +29 -0
  29. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Requests/UploadRequest.php +29 -0
  30. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Resources/BlockResource.php +39 -0
  31. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Resources/BlocksCollection.php +8 -0
  32. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Resources/PageResource.php +56 -0
  33. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Resources/PagesCollection.php +10 -0
  34. package/lib/generators/laravel-panneau/templates/app/Panneau/Http/Resources/UserResource.php +24 -0
  35. package/lib/generators/laravel-panneau/templates/app/Panneau/PanneauServiceProvider.php +48 -0
  36. package/lib/generators/laravel-panneau/templates/app/Panneau/Policies/PanneauPolicy.php +32 -0
  37. package/lib/generators/laravel-panneau/templates/app/Panneau/Resources/Blocks/BlockWithBlocks.php +110 -0
  38. package/lib/generators/laravel-panneau/templates/app/Panneau/Resources/Blocks/TextBlock.php +27 -0
  39. package/lib/generators/laravel-panneau/templates/app/Panneau/Resources/Blocks.php +42 -0
  40. package/lib/generators/laravel-panneau/templates/app/Panneau/Resources/Pages/Page.php +28 -0
  41. package/lib/generators/laravel-panneau/templates/app/Panneau/Resources/Pages.php +92 -0
  42. package/lib/generators/laravel-panneau/templates/app/Panneau/Resources/Users.php +57 -0
  43. package/lib/generators/laravel-panneau/templates/app/Repositories/Pages.php +42 -0
  44. package/lib/generators/laravel-panneau/templates/app/Resources/Blocks/TextBlock.php +14 -0
  45. package/lib/generators/laravel-panneau/templates/app/Resources/Page.php +10 -0
  46. package/lib/generators/laravel-panneau/templates/app/Resources/Pages/HomePage.php +10 -0
  47. package/lib/generators/laravel-panneau/templates/app.blade.php +8 -0
  48. package/lib/generators/laravel-panneau/templates/index.js +32 -0
  49. package/lib/generators/laravel-panneau/templates/lang/en/panneau.php +62 -0
  50. package/lib/generators/laravel-panneau/templates/lang/fr/panneau.php +62 -0
  51. package/lib/generators/laravel-panneau/templates/layout.blade.php +17 -48
  52. package/lib/generators/laravel-panneau/templates/resources/assets/js/components/Panneau.jsx +68 -0
  53. package/lib/generators/laravel-panneau/templates/{app/Schemas/Fields/.gitkeep → resources/assets/js/components/panneau/fields/PageSlug.jsx} +0 -0
  54. package/lib/generators/laravel-panneau/templates/resources/assets/js/components/panneau/fields/PageSlugLocalized.jsx +43 -0
  55. package/lib/generators/laravel-panneau/templates/resources/assets/js/components/panneau/fields/index.js +2 -0
  56. package/lib/generators/laravel-panneau/templates/resources/assets/styles/panneau.scss +2 -0
  57. package/lib/generators/laravel-panneau/templates/routes.php +30 -0
  58. package/lib/generators/laravel-project/index.js +504 -0
  59. package/lib/generators/laravel-project/templates/env +41 -0
  60. package/lib/generators/laravel-project/templates/laravel/app/Composers/AppComposer.php +48 -0
  61. package/lib/generators/laravel-project/templates/laravel/app/Composers/IntlComposer.php +10 -0
  62. package/lib/generators/laravel-project/templates/laravel/app/Composers/MetaComposer.php +48 -0
  63. package/lib/generators/laravel-project/templates/laravel/app/Composers/RoutesComposer.php +19 -0
  64. package/lib/generators/laravel-project/templates/laravel/app/Contracts/Resources/User.php +10 -0
  65. package/lib/generators/laravel-project/templates/laravel/app/Http/Controllers/HomeController.php +18 -0
  66. package/lib/generators/laravel-project/templates/laravel/app/Http/Middleware/TrustProxies.php +28 -0
  67. package/lib/generators/laravel-project/templates/laravel/app/Http/Resources/UserResource.php +21 -0
  68. package/lib/generators/laravel-project/templates/laravel/app/Models/User.php +50 -0
  69. package/lib/generators/laravel-project/templates/laravel/app/Providers/AppServiceProvider.php +45 -0
  70. package/lib/generators/laravel-project/templates/laravel/app/Providers/RouteServiceProvider.php +64 -0
  71. package/lib/generators/laravel-project/templates/laravel/app/Providers/ViewServiceProvider.php +33 -0
  72. package/lib/generators/laravel-project/templates/laravel/app/Repositories/Users.php +36 -0
  73. package/lib/generators/laravel-project/templates/laravel/app/Resources/User.php +11 -0
  74. package/lib/generators/laravel-project/templates/laravel/config/app.php +216 -0
  75. package/lib/generators/laravel-project/templates/laravel/config/auth.php +116 -0
  76. package/lib/generators/laravel-project/templates/laravel/config/services.php +39 -0
  77. package/lib/generators/laravel-project/templates/laravel/lang/en/content.php +5 -0
  78. package/lib/generators/laravel-project/templates/laravel/lang/en/errors.php +17 -0
  79. package/lib/generators/laravel-project/templates/laravel/lang/en/meta.php +11 -0
  80. package/lib/generators/laravel-project/templates/laravel/lang/en/routes.php +4 -0
  81. package/lib/generators/laravel-project/templates/laravel/lang/fr/auth.php +19 -0
  82. package/lib/generators/laravel-project/templates/laravel/lang/fr/content.php +5 -0
  83. package/lib/generators/laravel-project/templates/laravel/lang/fr/errors.php +17 -0
  84. package/lib/generators/laravel-project/templates/laravel/lang/fr/meta.php +11 -0
  85. package/lib/generators/laravel-project/templates/laravel/lang/fr/pagination.php +19 -0
  86. package/lib/generators/laravel-project/templates/laravel/lang/fr/passwords.php +22 -0
  87. package/lib/generators/laravel-project/templates/laravel/lang/fr/routes.php +12 -0
  88. package/lib/generators/laravel-project/templates/laravel/lang/fr/validation.php +146 -0
  89. package/lib/generators/laravel-project/templates/laravel/resources/assets/fonts/.gitkeep +0 -0
  90. package/lib/generators/laravel-project/templates/laravel/resources/assets/img/.gitkeep +0 -0
  91. package/lib/generators/laravel-project/templates/laravel/resources/assets/img/folklore.png +0 -0
  92. package/lib/generators/laravel-project/templates/laravel/resources/views/analytics/body.blade.php +3 -0
  93. package/lib/generators/laravel-project/templates/laravel/resources/views/analytics/gpt.blade.php +16 -0
  94. package/lib/generators/laravel-project/templates/laravel/resources/views/analytics/head.blade.php +1 -0
  95. package/lib/generators/laravel-project/templates/laravel/resources/views/app.blade.php +8 -0
  96. package/lib/generators/laravel-project/templates/laravel/resources/views/errors/401.blade.php +8 -0
  97. package/lib/generators/laravel-project/templates/laravel/resources/views/errors/403.blade.php +8 -0
  98. package/lib/generators/laravel-project/templates/laravel/resources/views/errors/404.blade.php +8 -0
  99. package/lib/generators/laravel-project/templates/laravel/resources/views/errors/500.blade.php +8 -0
  100. package/lib/generators/laravel-project/templates/laravel/resources/views/layout.blade.php +33 -0
  101. package/lib/generators/laravel-project/templates/laravel/resources/views/meta/all.blade.php +4 -0
  102. package/lib/generators/laravel-project/templates/laravel/resources/views/meta/base.blade.php +11 -0
  103. package/lib/generators/laravel-project/templates/laravel/resources/views/meta/facebook.blade.php +4 -0
  104. package/lib/generators/laravel-project/templates/laravel/resources/views/meta/opengraph.blade.php +9 -0
  105. package/lib/generators/laravel-project/templates/laravel/resources/views/meta/twitter.blade.php +5 -0
  106. package/lib/generators/laravel-project/templates/laravel/routes/web.php +12 -0
  107. package/lib/generators/react-app/templates/src/components/App.jsx +3 -2
  108. package/lib/generators/react-app/templates/src/components/pages/Error.jsx +2 -2
  109. package/lib/lib/generator.js +9 -0
  110. package/package.json +2 -2
  111. package/lib/generators/laravel-panneau/templates/_composer.json +0 -6
  112. package/lib/generators/laravel-panneau/templates/_package.json +0 -11
  113. package/lib/generators/laravel-panneau/templates/app/Http/Controllers/Panneau/HomeController.php +0 -14
  114. package/lib/generators/laravel-panneau/templates/app/Http/Controllers/Panneau/PagesController.php +0 -11
  115. package/lib/generators/laravel-panneau/templates/app/Models/Mediatheque/File.php +0 -13
  116. package/lib/generators/laravel-panneau/templates/app/Models/Mediatheque/Picture.php +0 -13
  117. package/lib/generators/laravel-panneau/templates/app/Models/Mediatheque/Video.php +0 -34
  118. package/lib/generators/laravel-panneau/templates/app/Providers/PanneauServiceProvider.php +0 -23
  119. package/lib/generators/laravel-panneau/templates/app/Reducers/SlugExtractReducer.php +0 -18
  120. package/lib/generators/laravel-panneau/templates/app/Resources/Pages.php +0 -54
  121. package/lib/generators/laravel-panneau/templates/app/Schemas/Blocks/Base.php +0 -22
  122. package/lib/generators/laravel-panneau/templates/app/Schemas/Bubbles/Base.php +0 -22
  123. package/lib/generators/laravel-panneau/templates/app/Schemas/Pages/Base.php +0 -36
  124. package/lib/generators/laravel-panneau/templates/resources/lang/en/panneau.php +0 -12
  125. package/lib/generators/laravel-panneau/templates/resources/lang/fr/panneau.php +0 -12
@@ -0,0 +1,22 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Fields;
4
+
5
+ use Panneau\Fields\ResourceItem;
6
+
7
+ class Block extends ResourceItem
8
+ {
9
+ public function resource(): string
10
+ {
11
+ return 'blocks';
12
+ }
13
+
14
+ public function attributes(): ?array
15
+ {
16
+ return array_merge(parent::attributes(), [
17
+ 'placeholder' => trans('panneau.fields.blocks_placeholder'),
18
+ 'itemLabelPath' => 'title',
19
+ 'itemDescriptionPath' => null,
20
+ ]);
21
+ }
22
+ }
@@ -0,0 +1,87 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Fields;
4
+
5
+ use Panneau\Fields\Items;
6
+ use Panneau\Fields\ResourceItem;
7
+ use App\Panneau\Resources\Blocks\BlockWithBlocks;
8
+
9
+ class Blocks extends Items
10
+ {
11
+ protected $currentDepth = 0;
12
+
13
+ protected $maxDepth = null;
14
+
15
+ protected $excludeTypes = [];
16
+
17
+ public function itemField(): ?string
18
+ {
19
+ return Block::class;
20
+ }
21
+
22
+ public function attributes(): ?array
23
+ {
24
+ // With types
25
+ $itemField = $this->itemField();
26
+ $itemField = !is_null($itemField) ? resolve($itemField) : null;
27
+ $itemResource =
28
+ !is_null($itemField) && $itemField instanceof ResourceItem
29
+ ? $itemField->makeResource()
30
+ : null;
31
+ $resourceTypes =
32
+ !is_null($itemResource) && $itemResource->hasTypes() ? $itemResource->getTypes() : null;
33
+
34
+ $attributes = [
35
+ 'withoutFormGroup' => true,
36
+ 'addItemLabel' => trans('panneau.fields.add_block'),
37
+ 'noItemLabel' => trans('panneau.fields.no_blocks'),
38
+ 'itemLabel' => trans('panneau.fields.block'),
39
+ 'withoutSort' => false,
40
+ ];
41
+
42
+ if (!is_null($resourceTypes)) {
43
+ $attributes['types'] = $resourceTypes
44
+ ->filter(function ($type) {
45
+ $key = get_class($type);
46
+ return !in_array($key, $this->excludeTypes);
47
+ })
48
+ ->map(function ($type) {
49
+ $hasBlocks = collect($type->fields())->contains(function ($field) {
50
+ return $field instanceof self;
51
+ });
52
+ if (isset($this->maxDepth) && $hasBlocks) {
53
+ return new BlockWithBlocks($type, $this->currentDepth + 1);
54
+ }
55
+ return $type;
56
+ })
57
+ ->filter(function ($type) {
58
+ if (isset($this->maxDepth) && $type instanceof BlockWithBlocks) {
59
+ return $type->currentDepth() < $this->maxDepth;
60
+ }
61
+ return true;
62
+ })
63
+ ->values()
64
+ ->toArray();
65
+ }
66
+
67
+ return $attributes;
68
+ }
69
+
70
+ public function maxDepth($depth)
71
+ {
72
+ $this->maxDepth = $depth;
73
+ return $this;
74
+ }
75
+
76
+ public function currentDepth($depth)
77
+ {
78
+ $this->currentDepth = $depth;
79
+ return $this;
80
+ }
81
+
82
+ public function withoutType($type)
83
+ {
84
+ $this->excludeTypes[] = is_object($type) ? get_class($type) : $type;
85
+ return $this;
86
+ }
87
+ }
@@ -0,0 +1,51 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Fields;
4
+
5
+ use Panneau\Fields\ResourceItem;
6
+
7
+ class Page extends ResourceItem
8
+ {
9
+ protected $query = [
10
+ 'paginated' => false,
11
+ ];
12
+
13
+ protected $pageTypes = [];
14
+
15
+ public function resource(): string
16
+ {
17
+ return 'pages';
18
+ }
19
+
20
+ public function component(): string
21
+ {
22
+ return 'item';
23
+ }
24
+
25
+ public function attributes(): ?array
26
+ {
27
+ $query = $this->query;
28
+ if (isset($this->pageTypes) && sizeof($this->pageTypes) > 0) {
29
+ $query['type'] = $this->pageTypes;
30
+ }
31
+
32
+ return array_merge(parent::attributes(), [
33
+ 'placeholder' => trans('panneau.forms.page_placeholder'),
34
+ 'itemLabelPath' => 'title.'.app()->getLocale(),
35
+ 'itemImagePath' => null,
36
+ 'requestQuery' => $query,
37
+ ]);
38
+ }
39
+
40
+ public function withQuery($query)
41
+ {
42
+ $this->query = $query;
43
+ return $this;
44
+ }
45
+
46
+ public function withTypes($types)
47
+ {
48
+ $this->pageTypes = is_array($types) ? $types : func_get_args();
49
+ return $this;
50
+ }
51
+ }
@@ -0,0 +1,34 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Fields;
4
+
5
+ use Panneau\Fields\Text;
6
+
7
+ class PageSlug extends Text
8
+ {
9
+ public function component(): string
10
+ {
11
+ return 'page-slug';
12
+ }
13
+
14
+ public function attributes(): ?array
15
+ {
16
+ $locale = app()->getLocale();
17
+ $locales = config('locale.locales');
18
+ $finalLocale = in_array($this->name, $locales) ? $this->name : $locale;
19
+
20
+ return array_merge(parent::attributes(), [
21
+ 'routes' => [
22
+ 'page' => url()->routeForReactRouter($finalLocale . '.page', [
23
+ 'withoutPatterns' => true,
24
+ ]),
25
+ 'page_with_parent' => url()->routeForReactRouter(
26
+ $finalLocale . '.page_with_parent',
27
+ [
28
+ 'withoutPatterns' => true,
29
+ ]
30
+ ),
31
+ ],
32
+ ]);
33
+ }
34
+ }
@@ -0,0 +1,18 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Fields;
4
+
5
+ use Panneau\Support\LocalizedField;
6
+
7
+ class PageSlugLocalized extends LocalizedField
8
+ {
9
+ public function component(): string
10
+ {
11
+ return 'page-slug-localized';
12
+ }
13
+
14
+ public function field($locale)
15
+ {
16
+ return new PageSlug($locale);
17
+ }
18
+ }
@@ -0,0 +1,41 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Http\Controllers;
4
+
5
+ use App\Http\Controllers\Controller;
6
+ use App\Http\Resources\UserResource;
7
+ use App\Panneau\Http\Requests\AccountUpdateRequest;
8
+ use Folklore\Contracts\Repositories\Users as UsersRepository;
9
+
10
+ class AccountController extends Controller
11
+ {
12
+ protected $users;
13
+
14
+ public function __construct(UsersRepository $users)
15
+ {
16
+ $this->users = $users;
17
+ }
18
+
19
+ /**
20
+ * Show the account
21
+ *
22
+ * @return \Illuminate\Contracts\Support\Renderable
23
+ */
24
+ public function index()
25
+ {
26
+ return view('panneau::app');
27
+ }
28
+
29
+ /**
30
+ * Update the account
31
+ *
32
+ * @return \Illuminate\Contracts\Support\Renderable
33
+ */
34
+ public function update(AccountUpdateRequest $request)
35
+ {
36
+ $data = $request->all();
37
+ $user = $request->user();
38
+ $user = $this->users->update($user->id(), $data);
39
+ return new UserResource($user);
40
+ }
41
+ }
@@ -0,0 +1,19 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Http\Controllers;
4
+
5
+ use Illuminate\Support\Str;
6
+ use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
7
+ use Illuminate\Foundation\Bus\DispatchesJobs;
8
+ use Illuminate\Foundation\Validation\ValidatesRequests;
9
+ use Illuminate\Routing\Controller as BaseController;
10
+
11
+ class Controller extends BaseController
12
+ {
13
+ use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
14
+
15
+ protected function requestIsJson($request)
16
+ {
17
+ return $request->wantsJson() || Str::endsWith($request->path(), '.json');
18
+ }
19
+ }
@@ -0,0 +1,16 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Http\Controllers;
4
+
5
+ class HomeController extends Controller
6
+ {
7
+ /**
8
+ * Show the home
9
+ *
10
+ * @return \Illuminate\Contracts\Support\Renderable
11
+ */
12
+ public function index()
13
+ {
14
+ return view('panneau::app');
15
+ }
16
+ }
@@ -0,0 +1,24 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Http\Controllers;
4
+
5
+ use Illuminate\Http\Request;
6
+ use Panneau\Contracts\Resource;
7
+ use Panneau\Http\Controllers\ResourceController;
8
+
9
+ class PagesController extends ResourceController
10
+ {
11
+ protected $defaultPageCount = 25;
12
+
13
+ protected function getResourceFromRequest(Request $request)
14
+ {
15
+ return app('panneau')->resource('pages');
16
+ }
17
+
18
+ protected function getIndexQueryFromRequest(Request $request, Resource $resource)
19
+ {
20
+ $query = parent::getIndexQueryFromRequest($request, $resource);
21
+
22
+ return $query;
23
+ }
24
+ }
@@ -0,0 +1,27 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Http\Controllers;
4
+
5
+ use App\Panneau\Http\Requests\UploadRequest;
6
+ use Folklore\Contracts\Repositories\Medias as MediasRepository;
7
+ use Folklore\Http\Resources\Medias\MediaResource;
8
+
9
+ class UploadController extends Controller
10
+ {
11
+ public function __construct(MediasRepository $medias)
12
+ {
13
+ $this->medias = $medias;
14
+ }
15
+
16
+ /**
17
+ * Show the account
18
+ *
19
+ * @return \Illuminate\Contracts\Support\Renderable
20
+ */
21
+ public function upload(UploadRequest $request)
22
+ {
23
+ $file = $request->file('file');
24
+ $media = $this->medias->createFromFile($file);
25
+ return new MediaResource($media);
26
+ }
27
+ }
@@ -0,0 +1,32 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Http\Controllers;
4
+
5
+ use Illuminate\Http\Request;
6
+ use Panneau\Http\Controllers\ResourceController;
7
+ use Panneau\Contracts\Resource;
8
+
9
+ class UsersController extends ResourceController
10
+ {
11
+ protected $defaultPageCount = 100;
12
+
13
+ protected function getResourceFromRequest(Request $request)
14
+ {
15
+ return app('panneau')->resource('users');
16
+ }
17
+
18
+ protected function getIndexQueryFromRequest(Request $request, Resource $resource)
19
+ {
20
+ $query = parent::getIndexQueryFromRequest($request, $resource);
21
+
22
+ if (!isset($query['order'])) {
23
+ $query['order'] = 'created_at';
24
+ }
25
+
26
+ if (!isset($query['role'])) {
27
+ $query['role'] = 'admin';
28
+ }
29
+
30
+ return $query;
31
+ }
32
+ }
@@ -0,0 +1,29 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Http\Requests;
4
+
5
+ use Illuminate\Foundation\Http\FormRequest;
6
+
7
+ class AccountUpdateRequest extends FormRequest
8
+ {
9
+ /**
10
+ * Determine if the user is authorized to make this request.
11
+ *
12
+ * @return bool
13
+ */
14
+ public function authorize()
15
+ {
16
+ $user = $this->user();
17
+ return !is_null($user);
18
+ }
19
+
20
+ /**
21
+ * Get the validation rules that apply to the request.
22
+ *
23
+ * @return array
24
+ */
25
+ public function rules()
26
+ {
27
+ return [];
28
+ }
29
+ }
@@ -0,0 +1,29 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Http\Requests;
4
+
5
+ use Illuminate\Foundation\Http\FormRequest;
6
+
7
+ class UploadRequest extends FormRequest
8
+ {
9
+ /**
10
+ * Determine if the user is authorized to make this request.
11
+ *
12
+ * @return bool
13
+ */
14
+ public function authorize()
15
+ {
16
+ $user = $this->user();
17
+ return !is_null($user);
18
+ }
19
+
20
+ /**
21
+ * Get the validation rules that apply to the request.
22
+ *
23
+ * @return array
24
+ */
25
+ public function rules()
26
+ {
27
+ return [];
28
+ }
29
+ }
@@ -0,0 +1,39 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Http\Resources;
4
+
5
+ use Illuminate\Http\Resources\Json\JsonResource;
6
+ use App\Contracts\Resources\HasBlocks;
7
+ use Folklore\Http\Resources\LocalizedResource;
8
+ use App\Contracts\Resources\Blocks\Text as TextBlock;
9
+
10
+ class BlockResource extends JsonResource
11
+ {
12
+ /**
13
+ * Transform the resource into an array.
14
+ *
15
+ * @param \Illuminate\Http\Request $request
16
+ * @return array
17
+ */
18
+ public function toArray($request)
19
+ {
20
+ $type = $this->type();
21
+
22
+ return [
23
+ 'id' => $this->id(),
24
+ 'type' => $type,
25
+ 'blocks' => $this->when($this->resource instanceof HasBlocks, function () {
26
+ $blocks = $this->blocks();
27
+ return !is_null($blocks) ? new BlocksCollection($blocks) : [];
28
+ }),
29
+
30
+ $this->mergeWhen($this->resource instanceof TextBlock, function () {
31
+ return [
32
+ 'body' => new LocalizedResource(function ($locale) {
33
+ return $this->body($locale);
34
+ }),
35
+ ];
36
+ }),
37
+ ];
38
+ }
39
+ }
@@ -0,0 +1,8 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Http\Resources;
4
+
5
+ class BlocksCollection extends Collection
6
+ {
7
+ public $collects = BlockResource::class;
8
+ }
@@ -0,0 +1,56 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Http\Resources;
4
+
5
+ use Illuminate\Http\Resources\Json\JsonResource;
6
+ use App\Http\Resources\Medias\ImageResource;
7
+ use App\Contracts\Resources\Page;
8
+ use App\Contracts\Resources\HasBlocks;
9
+ use Folklore\Http\Resources\LocalizedResource;
10
+ use App\Contracts\Resources\Pages\Home as HomePage;
11
+
12
+ class PageResource extends JsonResource
13
+ {
14
+ /**
15
+ * Transform the resource into an array.
16
+ *
17
+ * @param \Illuminate\Http\Request $request
18
+ * @return array
19
+ */
20
+ public function toArray($request)
21
+ {
22
+ $locale = $request->locale();
23
+ $isPanneauIndex = $request->isPanneauIndex();
24
+
25
+ return [
26
+ 'id' => $this->id(),
27
+ 'type' => $this->type(),
28
+ 'published' => $this->published(),
29
+ 'title' => new LocalizedResource(function ($locale) {
30
+ return $this->title($locale);
31
+ }),
32
+ 'description' => new LocalizedResource(function ($locale) {
33
+ return $this->description($locale);
34
+ }),
35
+ 'slug' => new LocalizedResource(function ($locale) {
36
+ return $this->slug($locale);
37
+ }),
38
+ 'image' => !is_null($image) ? new ImageResource($image) : null,
39
+ 'parent' =>
40
+ !is_null($parent) && $parent instanceof Page
41
+ ? new ParentPageResource($parent)
42
+ : null,
43
+
44
+ $this->mergeWhen($this->resource instanceof HasBlocks, function () {
45
+ $blocks = $this->blocks();
46
+ return [
47
+ 'blocks' => !is_null($blocks) ? new BlocksCollection($blocks) : [],
48
+ ];
49
+ }),
50
+
51
+ $this->mergeWhen($this->resource instanceof HomePage, function () {
52
+ return [];
53
+ }),
54
+ ];
55
+ }
56
+ }
@@ -0,0 +1,10 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Http\Resources;
4
+
5
+ use Folklore\Http\Resources\Collection;
6
+
7
+ class PagesCollection extends Collection
8
+ {
9
+ public $collects = PageResource::class;
10
+ }
@@ -0,0 +1,24 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Http\Resources;
4
+
5
+ use Illuminate\Http\Resources\Json\JsonResource;
6
+
7
+ class UserResource extends JsonResource
8
+ {
9
+ /**
10
+ * Transform the resource into an array.
11
+ *
12
+ * @param \Illuminate\Http\Request $request
13
+ * @return array
14
+ */
15
+ public function toArray($request)
16
+ {
17
+ return [
18
+ 'id' => $this->id(),
19
+ 'name' => $this->name(),
20
+ 'email' => $this->email(),
21
+ 'role' => $this->role(),
22
+ ];
23
+ }
24
+ }
@@ -0,0 +1,48 @@
1
+ <?php
2
+
3
+ namespace App\Panneau;
4
+
5
+ use Illuminate\Support\ServiceProvider as BaseServiceProvider;
6
+ use Illuminate\Contracts\View\Factory as ViewFactory;
7
+ use Illuminate\Support\Facades\Gate;
8
+ use Panneau\Support\LocalizedField;
9
+ use Panneau\Support\Facade as Panneau;
10
+
11
+ class PanneauServiceProvider extends BaseServiceProvider
12
+ {
13
+ /**
14
+ * Register any application services.
15
+ *
16
+ * @return void
17
+ */
18
+ public function register()
19
+ {
20
+ Gate::policy(\Panneau\Panneau::class, \App\Panneau\Policies\PanneauPolicy::class);
21
+ }
22
+
23
+ /**
24
+ * Bootstrap any application services.
25
+ *
26
+ * @return void
27
+ */
28
+ public function boot()
29
+ {
30
+ LocalizedField::setLocalesResolver(function () {
31
+ return config('locale.locales');
32
+ });
33
+
34
+ $this->bootViews();
35
+ }
36
+
37
+ protected function bootViews()
38
+ {
39
+ $view = $this->app[ViewFactory::class];
40
+
41
+ // Panneau
42
+ $view->composer('panneau::app', \App\Panneau\Composers\AppComposer::class);
43
+
44
+ Panneau::serving(function () use ($view) {
45
+ $view->composer('errors::*', \App\Panneau\Composers\AppComposer::class);
46
+ });
47
+ }
48
+ }
@@ -0,0 +1,32 @@
1
+ <?php
2
+
3
+ namespace App\Panneau\Policies;
4
+
5
+ use Illuminate\Auth\Access\HandlesAuthorization;
6
+ use App\Contracts\Resources\User;
7
+
8
+ class PanneauPolicy
9
+ {
10
+ use HandlesAuthorization;
11
+
12
+ /**
13
+ * Create a new policy instance.
14
+ *
15
+ * @return void
16
+ */
17
+ public function __construct()
18
+ {
19
+ //
20
+ }
21
+
22
+ /**
23
+ * Determine if panneau can be viewed by the user.
24
+ *
25
+ * @param \App\User $user
26
+ * @return bool
27
+ */
28
+ public function view(User $user)
29
+ {
30
+ return $user->role() === 'admin';
31
+ }
32
+ }