Skip to content

Commit a2e4f87

Browse files
committed
Core and Builder assets and docs
1 parent aab8280 commit a2e4f87

File tree

7 files changed

+201
-6
lines changed

7 files changed

+201
-6
lines changed

art/screenshot/builder-item.jpg

131 KB
Loading

packages/builder/README.md

Lines changed: 176 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
<!--shortdesc-->
66

7-
This template is used for generating all Moox packages. Press the Template-Button in GitHub, to create your own.
8-
9-
If you install it, it will completely work without beeing useful. Guaranteed!
7+
This template is used for generating Moox packages. Press the Template-Button in GitHub, create your own Laravel and Filament package.
108

119
<!--/shortdesc-->
1210

@@ -25,7 +23,181 @@ Curious what the install command does? See manual installation below.
2523

2624
<!--whatdoes-->
2725

28-
Here are some things missing, like an overview with screenshots about this package, or simply a link to the package's docs.
26+
This Laravel Package Template can be used to create a package including a powerful Filament resource called Item.
27+
28+
![Moox Builder Item](https://github.com/mooxphp/moox/raw/main/art/screenshot/builder-item.jpg)
29+
30+
Name and table for the Resource can be changed while building your package.
31+
32+
### Using the Template
33+
34+
1. Go to https://github.com/mooxphp/builder
35+
2. Press the `Use this template` button
36+
3. Create a new repository based on the template
37+
4. Clone the repository locally
38+
5. Run `php build.php`in the repo's directory and follow the steps
39+
- Author Name (Default: Moox Developer): Your Name
40+
- Author Email (Default: dev@moox.org): your@mail.com
41+
- Package Name (Default: Blog Package): Your Package
42+
- Package Description (Default: This is my package Blog Package)
43+
- Package Entity (Default: Item): e.g. Post
44+
- Tablename (Default: items): e.g. posts
45+
46+
After building the package, you can push the changes to GitHub and create an installable package on Packagist.org. Don't forget to adjust the README to your composer namespace.
47+
48+
### Config
49+
50+
After that the Resource is highly configurable.
51+
52+
#### Tabs and Translation
53+
54+
Moox Core features like Dynamic Tabs and Translatable Config. See the config file for more details, but as a quick example:
55+
56+
```php
57+
/*
58+
|--------------------------------------------------------------------------
59+
| Tabs
60+
|--------------------------------------------------------------------------
61+
|
62+
| Define the tabs for the Resource table. They are optional, but
63+
| pretty awesome to filter the table by certain values.
64+
| You may simply do a 'tabs' => [], to disable them.
65+
|
66+
*/
67+
68+
'tabs' => [
69+
'all' => [
70+
'label' => 'trans//core::core.all',
71+
'icon' => 'gmdi-filter-list',
72+
'query' => [
73+
[
74+
'field' => 'deleted_at',
75+
'operator' => '=',
76+
'value' => null,
77+
],
78+
],
79+
],
80+
'published' => [
81+
'label' => 'trans//core::core.published',
82+
'icon' => 'gmdi-check-circle',
83+
'query' => [
84+
[
85+
'field' => 'publish_at',
86+
'operator' => '<=',
87+
'value' => function () {
88+
return now();
89+
},
90+
],
91+
[
92+
'field' => 'deleted_at',
93+
'operator' => '=',
94+
'value' => null,
95+
],
96+
],
97+
],
98+
'scheduled' => [
99+
'label' => 'trans//core::core.scheduled',
100+
'icon' => 'gmdi-schedule',
101+
'query' => [
102+
[
103+
'field' => 'publish_at',
104+
'operator' => '>',
105+
'value' => function () {
106+
return now();
107+
},
108+
],
109+
[
110+
'field' => 'deleted_at',
111+
'operator' => '=',
112+
'value' => null,
113+
],
114+
],
115+
],
116+
'draft' => [
117+
'label' => 'trans//core::core.draft',
118+
'icon' => 'gmdi-text-snippet',
119+
'query' => [
120+
[
121+
'field' => 'publish_at',
122+
'operator' => '=',
123+
'value' => null,
124+
],
125+
[
126+
'field' => 'deleted_at',
127+
'operator' => '=',
128+
'value' => null,
129+
],
130+
],
131+
],
132+
'deleted' => [
133+
'label' => 'trans//core::core.deleted',
134+
'icon' => 'gmdi-delete',
135+
'query' => [
136+
[
137+
'field' => 'deleted_at',
138+
'operator' => '!=',
139+
'value' => null,
140+
],
141+
],
142+
],
143+
],
144+
],
145+
```
146+
147+
All options for Tabs are explained in [Moox Core docs](https://github.com/mooxphp/core/blob/main/README.md#dynamic-tabs).
148+
149+
#### Item Types
150+
151+
The item also support 'item' types, means you are able to configure selectable types for your Entity. By default, we provide "Post" and "Page" as example. If you don't want to use types, just empty the array and the field and column become invisible.
152+
153+
```php
154+
/*
155+
|--------------------------------------------------------------------------
156+
| Item Types
157+
|--------------------------------------------------------------------------
158+
|
159+
| This array contains the types of items entities. You can delete
160+
| the types you don't need and add new ones. If you don't need
161+
| types, you can empty this array like this: 'types' => [],
162+
|
163+
*/
164+
165+
'types' => [
166+
'post' => 'Post',
167+
'page' => 'Page',
168+
],
169+
```
170+
171+
#### Author Model
172+
173+
You can configure the user model used for displaying Authors. By default it is tied to App User:
174+
175+
```php
176+
/*
177+
|--------------------------------------------------------------------------
178+
| Author Model
179+
|--------------------------------------------------------------------------
180+
|
181+
| This sets the user model that can be used as author. It should be an
182+
| authenticatable model and support the morph relationship.
183+
| It should have fields similar to Moox User or WpUser.
184+
|
185+
*/
186+
187+
'author_model' => \App\Models\User::class,
188+
```
189+
190+
You may probably use Moox User
191+
192+
```php
193+
'author_model' => \Moox\User\Models\User::class,
194+
```
195+
196+
or Moox Press User instead:
197+
198+
```php
199+
'author_model' => \Moox\Press\Models\WpUser::class,
200+
```
29201

30202
<!--/whatdoes-->
31203

packages/builder/src/Resources/ItemResource.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public static function form(Form $form): Form
165165
Select::make('type')
166166
->options(static::getModel()::getTypeOptions())
167167
->default('post')
168+
->visible(! empty(config('builder.types')))
168169
->required(),
169170
DateTimePicker::make('publish_at')
170171
->label(__('core::core.publish_at')),
@@ -195,12 +196,14 @@ public static function table(Table $table): Table
195196
->columns([
196197
ImageColumn::make('featured_image_url')
197198
->label(__('core::core.image'))
199+
->defaultImageUrl(url('/moox/core/assets/noimage.svg'))
198200
->alignment('center')
199201
->square()
200202
->toggleable(),
201203
TextColumn::make('title')
202204
->label(__('core::core.title'))
203205
->searchable()
206+
->limit(30)
204207
->toggleable()
205208
->sortable(),
206209
TextColumn::make('slug')
@@ -211,6 +214,7 @@ public static function table(Table $table): Table
211214
TextColumn::make('content')
212215
->label(__('core::core.content'))
213216
->sortable()
217+
->limit(30)
214218
->searchable()
215219
->toggleable(),
216220
ImageColumn::make('author.avatar_url')
@@ -222,7 +226,8 @@ public static function table(Table $table): Table
222226
->toggleable(),
223227
TextColumn::make('type')
224228
->label(__('core::core.type'))
225-
->toggleable(isToggledHiddenByDefault: true)
229+
->visible(! empty(config('builder.types')))
230+
->formatStateUsing(fn ($record): string => config('builder.types')[$record->type] ?? ucfirst($record->type))
226231
->sortable(),
227232
TextColumn::make('status')
228233
->label(__('core::core.status'))

packages/core/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,10 @@ You can enable shared hosting features. This is useful if you want to run schedu
544544
],
545545
```
546546

547+
## Assets
548+
549+
Moox Core provides a couple of (non-publishable) assets, loaded by a dynamic route. All images and assets in /public can be used like `url('/moox/core/assets/noimage.svg'`.
550+
547551
## Changelog
548552

549553
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

packages/core/public/noimage.svg

Lines changed: 3 additions & 0 deletions
Loading

packages/core/routes/web.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
Route::get('moox/core/assets/{filename}', function ($filename) {
4+
$path = base_path('vendor/moox/core/public/'.$filename);
5+
6+
if (file_exists($path)) {
7+
return response()->file($path);
8+
}
9+
10+
abort(404);
11+
});

packages/core/src/CoreServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function configurePackage(Package $package): void
3737
->name('core')
3838
->hasConfigFile()
3939
->hasTranslations()
40-
->hasRoute('api')
40+
->hasRoutes(['api', 'web'])
4141
->hasCommand(InstallCommand::class);
4242
}
4343

0 commit comments

Comments
 (0)