Skip to content

Commit f5d3bac

Browse files
committed
feat: add docs for new serve command
1 parent 0603a07 commit f5d3bac

File tree

3 files changed

+104
-105
lines changed

3 files changed

+104
-105
lines changed

src/docs/frontend/inertia.md

Lines changed: 25 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ To get started, you can run:
1212

1313
::: code-group
1414

15-
```bash:no-line-numbers [Leaf CLI]
16-
leaf view:install
17-
```
18-
1915
```bash:no-line-numbers [Leaf MVC CLI]
2016
php leaf view:install
2117
```
2218

19+
```bash:no-line-numbers [Leaf CLI]
20+
leaf view:install
21+
```
22+
2323
:::
2424

2525
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
2828

2929
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:
3030

31-
```bash
31+
```bash:no-line-numbers
3232
php leaf view:install --vue
3333
```
3434

3535
:::
3636

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:
3838

3939
::: code-group
4040

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
5543
```
5644

57-
:::
58-
59-
And then your main Leaf server which will run your app:
60-
61-
::: code-group
62-
6345
```bash:no-line-numbers [Leaf CLI]
6446
leaf serve
6547
```
6648

67-
```bash:no-line-numbers [Leaf MVC CLI]
68-
php leaf serve
69-
```
70-
7149
:::
7250

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-
7551
## Setting up your routes
7652

7753
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
166142

167143
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.
168144

169-
### Setting up Vite
145+
### 1. Setting up Vite
170146

171147
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).
172148

173-
```bash
149+
```bash:no-line-numbers
174150
npm i -D vite @leafphp/vite-plugin
175151
leaf install vite
176152
```
177153

178-
### Vite Config
154+
### 2. Vite Config
179155

180156
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.
181157

@@ -201,26 +177,28 @@ leaf({
201177
}),
202178
```
203179

204-
### Setting up Inertia
180+
### 3. Setting up Inertia
205181

206182
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:
207183

208-
```bash
184+
```bash:no-line-numbers
209185
npm i react react-dom @inertiajs/react @vitejs/plugin-react
210186
```
211187

212188
You should also install the Leaf Inertia PHP adapter:
213189

214-
```bash
190+
::: code-group
191+
192+
```bash:no-line-numbers [Leaf CLI]
215193
leaf install inertia
216194
```
217195

218-
Or with composer:
219-
220-
```bash
196+
```bash:no-line-numbers [Composer]
221197
composer require leafs/inertia
222198
```
223199

200+
:::
201+
224202
After adding the React Vite plugin, you should add it to your vite config file:
225203

226204
```js{3,10}
@@ -238,7 +216,7 @@ export default defineConfig({
238216
});
239217
```
240218

241-
### Setting up your base JavaScript file
219+
### 4. Setting up your base JavaScript file
242220

243221
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:
244222

@@ -272,17 +250,17 @@ setup({ el, App, props }) {
272250
},
273251
```
274252

275-
### Setting up your base PHP file
253+
### 5. Setting up your base PHP file
276254

277255
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.
278256

279-
```php
257+
```php:no-line-numbers
280258
Inertia::setRoot('myfiles/_base');
281259
```
282260

283261
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:
284262

285-
```php
263+
```blade
286264
<!DOCTYPE html>
287265
<html lang="en">
288266
@@ -324,11 +302,11 @@ Since the Leaf Inertia PHP adapter is built using the [Bare UI engine](/docs/fro
324302

325303
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:
326304

327-
```bash
305+
```bash:no-line-numbers
328306
leaf view:install --inertia
329307
```
330308

331-
### Setting up your frontend framework
309+
### 6. Setting up your frontend framework
332310

333311
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:
334312

src/docs/frontend/vite.md

Lines changed: 58 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,51 +18,13 @@ Check out these articles from SitePoint and Next JS:
1818

1919
## Setting Up
2020

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:
2222

2323
```bash:no-line-numbers
2424
leaf view:install --vite
2525
```
2626

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.
6628

6729
## Loading your assets
6830

@@ -76,7 +38,7 @@ Here's an example of how you can load a CSS file:
7638
::: code-group
7739

7840
```blade:no-line-numbers [Blade]
79-
{{ vite('css/app.css') }}
41+
@vite('css/app.css')
8042
```
8143

8244
```php:no-line-numbers [BareUI]
@@ -90,7 +52,7 @@ You can also load multiple assets at once by passing in an array of assets:
9052
::: code-group
9153

9254
```blade:no-line-numbers [Blade]
93-
{{ vite(['app.css', 'app.js']) }}
55+
@vite(['app.css', 'app.js'])
9456
```
9557

9658
```php:no-line-numbers [BareUI]
@@ -137,7 +99,23 @@ Unlike the `vite.config.js` file, this configuration is done in PHP and is compl
13799

138100
## Running Vite
139101

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:
141119

142120
::: code-group
143121

@@ -157,11 +135,9 @@ pnpm i && pnpm run dev
157135
yarn && yarn dev
158136
```
159137

160-
:::
161-
162138
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.
163139

164-
**You need to keep the Vite server running in a separate terminal window while you work on your project.**
140+
:::
165141

166142
## Adding Aliases
167143

@@ -192,3 +168,39 @@ export default defineConfig({
192168
## Vite + other frameworks
193169

194170
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).

src/docs/mvc/commands.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,32 @@ class CachePurgeCommand extends Command
8282
}
8383
```
8484

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.
8686

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
9189

92-
```bash:no-line-numbers [Leaf CLI]
93-
leaf install aloe mvc-core
94-
```
90+
namespace App\Console;
9591

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+
}
98109
```
99110

100-
:::
101-
102111
## Command Arguments
103112

104113
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

Comments
 (0)