You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/docs/frontend/inertia.md
+25-47Lines changed: 25 additions & 47 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,14 +12,14 @@ To get started, you can run:
12
12
13
13
::: code-group
14
14
15
-
```bash:no-line-numbers [Leaf CLI]
16
-
leaf view:install
17
-
```
18
-
19
15
```bash:no-line-numbers [Leaf MVC CLI]
20
16
php leaf view:install
21
17
```
22
18
19
+
```bash:no-line-numbers [Leaf CLI]
20
+
leaf view:install
21
+
```
22
+
23
23
:::
24
24
25
25
This will prompt you to select your preferred frontend framework. You can choose from Vue, React, and Svelte. There is also support for styling with Tailwind/Bootstrap. After selecting your preferred framework, Leaf will automatically install and setup inertia for you, including examples for you to get started with.
@@ -28,50 +28,26 @@ This will prompt you to select your preferred frontend framework. You can choose
28
28
29
29
If you know the specific frontend framework you want to use, you can pass the `--{framework}` flag to the `view:install` command. For example, to install inertia for Vue, you can run:
30
30
31
-
```bash
31
+
```bash:no-line-numbers
32
32
php leaf view:install --vue
33
33
```
34
34
35
35
:::
36
36
37
-
To run your app, you'll need to start two servers. One to actively bundle your frontend dependencies (your framework, styles, ...):
37
+
You can then start your server which will automatically start both your Leaf server and your frontend server:
38
38
39
39
::: code-group
40
40
41
-
```bash:no-line-numbers [Leaf CLI]
42
-
leaf view:dev
43
-
```
44
-
45
-
```bash:no-line-numbers [npm]
46
-
npm i && npm run dev
47
-
```
48
-
49
-
```bash:no-line-numbers [pnpm]
50
-
pnpm i && pnpm run dev
51
-
```
52
-
53
-
```bash:no-line-numbers [yarn]
54
-
yarn && yarn dev
41
+
```bash:no-line-numbers [Leaf MVC CLI]
42
+
php leaf serve
55
43
```
56
44
57
-
:::
58
-
59
-
And then your main Leaf server which will run your app:
60
-
61
-
::: code-group
62
-
63
45
```bash:no-line-numbers [Leaf CLI]
64
46
leaf serve
65
47
```
66
48
67
-
```bash:no-line-numbers [Leaf MVC CLI]
68
-
php leaf serve
69
-
```
70
-
71
49
:::
72
50
73
-
If you want to read more on why 2 servers are necessary, you can check out the [Leaf + Vite documentation](/docs/frontend/vite#vite-other-frameworks)
74
-
75
51
## Setting up your routes
76
52
77
53
Adding Inertia to your Leaf app doesn't change the way you handle routing, it just replaces your PHP views with your frontend framework. This means you are still going to use Leaf's routing system to handle your routes:
@@ -166,16 +142,16 @@ You can find more information on using Inertia with your frontend framework in t
166
142
167
143
If you don't want to use the Leaf CLI, you can manually setup inertia. This guide will show you how to setup inertia with Vite and React. You can use this guide to setup inertia with any frontend framework.
168
144
169
-
### Setting up Vite
145
+
### 1. Setting up Vite
170
146
171
147
To get started, you need to setup Vite. We have a Leaf plugin that takes care of a lot of the heavy lifting for you. We have a detailed guide on how to setup vite with Leaf [here](/docs/frontend/vite).
172
148
173
-
```bash
149
+
```bash:no-line-numbers
174
150
npm i -D vite @leafphp/vite-plugin
175
151
leaf install vite
176
152
```
177
153
178
-
### Vite Config
154
+
### 2. Vite Config
179
155
180
156
The [Leaf Vite docs](/docs/frontend/vite#vite-config) have a detailed guide on how to setup vite config files. You should however note that for the best developer experience, you should point Vite to your view directory so you can enjoy hot module reloading.
181
157
@@ -201,26 +177,28 @@ leaf({
201
177
}),
202
178
```
203
179
204
-
### Setting up Inertia
180
+
### 3. Setting up Inertia
205
181
206
182
To setup inertia, you need to install the inertia package for whatever frontend framework you want to use, together with the Vite plugin for that framework. For example, if you want to use React, you should install the Inertia React package, React Vite plugin as well as React itself:
207
183
208
-
```bash
184
+
```bash:no-line-numbers
209
185
npm i react react-dom @inertiajs/react @vitejs/plugin-react
210
186
```
211
187
212
188
You should also install the Leaf Inertia PHP adapter:
213
189
214
-
```bash
190
+
::: code-group
191
+
192
+
```bash:no-line-numbers [Leaf CLI]
215
193
leaf install inertia
216
194
```
217
195
218
-
Or with composer:
219
-
220
-
```bash
196
+
```bash:no-line-numbers [Composer]
221
197
composer require leafs/inertia
222
198
```
223
199
200
+
:::
201
+
224
202
After adding the React Vite plugin, you should add it to your vite config file:
225
203
226
204
```js{3,10}
@@ -238,7 +216,7 @@ export default defineConfig({
238
216
});
239
217
```
240
218
241
-
### Setting up your base JavaScript file
219
+
### 4. Setting up your base JavaScript file
242
220
243
221
You should create a base JavaScript file that will be used to mount your app. This file should import your CSS and other assets. For example, if you're using React, your base JavaScript file should look like this:
244
222
@@ -272,17 +250,17 @@ setup({ el, App, props }) {
272
250
},
273
251
```
274
252
275
-
### Setting up your base PHP file
253
+
### 5. Setting up your base PHP file
276
254
277
255
You should create a base PHP file that will be used to render your app. By default, the Leaf Inertia PHP adapter will look for a file named `_inertia.view.php` in your views directory. You can change this by passing the path to your base PHP file to the `Inertia::setRoot` method.
278
256
279
-
```php
257
+
```php:no-line-numbers
280
258
Inertia::setRoot('myfiles/_base');
281
259
```
282
260
283
261
Since the Leaf Inertia PHP adapter is built using the [Bare UI engine](/docs/frontend/bareui), your base file needs to maintain the `.view.php` extension. For example, if you're using React, your base PHP file should look like this:
284
262
285
-
```php
263
+
```blade
286
264
<!DOCTYPE html>
287
265
<html lang="en">
288
266
@@ -324,11 +302,11 @@ Since the Leaf Inertia PHP adapter is built using the [Bare UI engine](/docs/fro
324
302
325
303
This might look pretty ugly, but you'll never have to touch this file again. You can also use the Leaf CLI to generate this file for you:
326
304
327
-
```bash
305
+
```bash:no-line-numbers
328
306
leaf view:install --inertia
329
307
```
330
308
331
-
### Setting up your frontend framework
309
+
### 6. Setting up your frontend framework
332
310
333
311
In the setup above, we told Inertia to look for our frontend framework files in `./DIRECTORYFORCOMPONENTS/`. You should create this directory and add your frontend framework files to it. For example, if you're using React, you should create a file named `Home.jsx` in this directory:
Copy file name to clipboardExpand all lines: src/docs/frontend/vite.md
+58-46Lines changed: 58 additions & 46 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,51 +18,13 @@ Check out these articles from SitePoint and Next JS:
18
18
19
19
## Setting Up
20
20
21
-
You can install the Vite module with the Leaf CLI:
21
+
Leaf MVC comes with Vite pre-installed, so you only need to start your server and you're good to go. If you are not using Leaf MVC, you can setup Vite using the Leaf CLI:
22
22
23
23
```bash:no-line-numbers
24
24
leaf view:install --vite
25
25
```
26
26
27
-
This command will install vite and the vite-leaf plugin, and will also install the vite module which will be used to load your assets on the server side. It will also create a vite config file at the root of your project. This config file can be used to configure vite, add plugins and more.
28
-
29
-
If you are using Leaf MVC, all of this is done for you automatically. You just need to start your Vite server and add your assets.
30
-
31
-
## Manually Installing Vite
32
-
33
-
If you don't have the Leaf CLI installed, you can manually install Vite although it's a bit more complex. First, you need to install all the JavaScript dependencies:
34
-
35
-
::: code-group
36
-
37
-
```bash:no-line-numbers [npm]
38
-
npm i -D vite @leafphp/vite-plugin
39
-
```
40
-
41
-
```bash:no-line-numbers [pnpm]
42
-
pnpm i -D vite @leafphp/vite-plugin
43
-
```
44
-
45
-
```bash:no-line-numbers [yarn]
46
-
yarn add -D vite @leafphp/vite-plugin
47
-
```
48
-
49
-
:::
50
-
51
-
After that, you need to install the server component for Vite. This will allow you to load your assets on the server side using PHP. You can install this by running:
52
-
53
-
::: code-group
54
-
55
-
```bash:no-line-numbers [Leaf CLI]
56
-
leaf install vite
57
-
```
58
-
59
-
```bash:no-line-numbers [Composer]
60
-
composer require leafs/vite
61
-
```
62
-
63
-
:::
64
-
65
-
Finally, Vite requires a configuration file to run. You can create a `vite.config.js` file at the root of your project and add your configuration there. You can learn more about Vite configuration files [here](#vite-config).
27
+
This command will install vite, and the leaf-vite module which will be used to load your assets on the server side plus all vite-specific dependencies and config files.
66
28
67
29
## Loading your assets
68
30
@@ -76,7 +38,7 @@ Here's an example of how you can load a CSS file:
76
38
::: code-group
77
39
78
40
```blade:no-line-numbers [Blade]
79
-
{{ vite('css/app.css') }}
41
+
@vite('css/app.css')
80
42
```
81
43
82
44
```php:no-line-numbers [BareUI]
@@ -90,7 +52,7 @@ You can also load multiple assets at once by passing in an array of assets:
90
52
::: code-group
91
53
92
54
```blade:no-line-numbers [Blade]
93
-
{{ vite(['app.css', 'app.js']) }}
55
+
@vite(['app.css', 'app.js'])
94
56
```
95
57
96
58
```php:no-line-numbers [BareUI]
@@ -137,7 +99,23 @@ Unlike the `vite.config.js` file, this configuration is done in PHP and is compl
137
99
138
100
## Running Vite
139
101
140
-
Vite comes with a development server that you can use to serve your frontend assets. This is a bit different from the traditional way of serving assets with PHP because you need to run a separate server for your assets. You can start your Vite server by running:
102
+
Vite comes with a development server that you can use to serve your frontend assets which is separate from your PHP server. If you use Leaf MVC or the Leaf CLI, this server will be automatically fired up when you run the serve command:
103
+
104
+
::: code-group
105
+
106
+
```bash:no-line-numbers [Leaf MVC CLI]
107
+
php leaf serve
108
+
```
109
+
110
+
```bash:no-line-numbers [Leaf CLI]
111
+
leaf serve
112
+
```
113
+
114
+
:::
115
+
116
+
::: details Running Vite manually
117
+
118
+
If you are not using Leaf MVC, you need to start the Vite server manually in a separate terminal process:
141
119
142
120
::: code-group
143
121
@@ -157,11 +135,9 @@ pnpm i && pnpm run dev
157
135
yarn && yarn dev
158
136
```
159
137
160
-
:::
161
-
162
138
This will install the necessary dependencies and start your Vite server. You don't need to do anything with the Vite server, just keep it running in the background and Leaf will take care of the rest.
163
139
164
-
**You need to keep the Vite server running in a separate terminal window while you work on your project.**
Using a combination of Leaf and Vite, you can use React with your favourite frontend technologies like React, Vue and Svelte. We've added a guide to setting up frontend frameworks using Inertia [over here](/docs/frontend/inertia).
171
+
172
+
## Manually Installing Vite
173
+
174
+
If you don't have the Leaf CLI installed, you can manually install Vite although it's a bit more complex. First, you need to install all the JavaScript dependencies:
175
+
176
+
::: code-group
177
+
178
+
```bash:no-line-numbers [npm]
179
+
npm i -D vite @leafphp/vite-plugin
180
+
```
181
+
182
+
```bash:no-line-numbers [pnpm]
183
+
pnpm i -D vite @leafphp/vite-plugin
184
+
```
185
+
186
+
```bash:no-line-numbers [yarn]
187
+
yarn add -D vite @leafphp/vite-plugin
188
+
```
189
+
190
+
:::
191
+
192
+
After that, you need to install the server component for Vite. This will allow you to load your assets on the server side using PHP. You can install this by running:
193
+
194
+
::: code-group
195
+
196
+
```bash:no-line-numbers [Leaf CLI]
197
+
leaf install vite
198
+
```
199
+
200
+
```bash:no-line-numbers [Composer]
201
+
composer require leafs/vite
202
+
```
203
+
204
+
:::
205
+
206
+
Finally, Vite requires a configuration file to run. You can create a `vite.config.js` file at the root of your project and add your configuration there. You can learn more about Vite configuration files [here](#vite-config).
Copy file name to clipboardExpand all lines: src/docs/mvc/commands.md
+21-12Lines changed: 21 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -82,23 +82,32 @@ class CachePurgeCommand extends Command
82
82
}
83
83
```
84
84
85
-
Be sure to keep your command class in the `App\Console` namespace and extend the `Command` class and in the `app/console` directory. Once you've created your command, Leaf MVC will automatically load it when you run the `php leaf` console.
85
+
If you are using Leaf MVC v3.8 and above, the command is automatically loaded by Leaf MVC, but Leaf MVC v3.7 and below require you to register your new command in the `app/console/Commands.php` file.
86
86
87
-
::: details Commands not auto-loading?
88
-
If your command is not auto-loading, make sure you have the latest versions of MVC Core and Aloe installed.
89
-
90
-
::: code-group
87
+
```php
88
+
<?php
91
89
92
-
```bash:no-line-numbers [Leaf CLI]
93
-
leaf install aloe mvc-core
94
-
```
90
+
namespace App\Console;
95
91
96
-
```bash:no-line-numbers [Composer]
97
-
composer require leafs/aloe leafs/mvc-core
92
+
class Commands
93
+
{
94
+
/**
95
+
* Register commands
96
+
*
97
+
* @param $console
98
+
* @return void
99
+
*
100
+
*/
101
+
public static function register($console): void
102
+
{
103
+
$console->register([
104
+
ExampleCommand::class,
105
+
CachePurgeCommand::class
106
+
]);
107
+
}
108
+
}
98
109
```
99
110
100
-
:::
101
-
102
111
## Command Arguments
103
112
104
113
Command arguments are values that are passed to the command when it is run in the console. For example, if you have a command named `example` and you run it like this:
0 commit comments