Skip to content

Commit 539416c

Browse files
committed
feat: add new Leaf MVC docs
1 parent 1a57448 commit 539416c

File tree

5 files changed

+100
-13
lines changed

5 files changed

+100
-13
lines changed

src/docs/database/builder.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,25 @@ db()
348348
->all();
349349
```
350350

351+
## Counting results
352+
353+
You can count the number of results returned by a query using the `count()` method.
354+
355+
```php
356+
db()
357+
->select('users')
358+
->count();
359+
```
360+
361+
Or even with complex queries:
362+
363+
```php
364+
db()
365+
->select('users')
366+
->where('age', '>', 20)
367+
->count();
368+
```
369+
351370
## Error Handling
352371

353372
There are lots of times where your query might fail. This could be because of a syntax error, a missing table, or a missing column. Leaf DB provides an `errors()` method that allows you to get the error message if your query fails.

src/docs/database/redis.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ composer require leafs/redis
4343

4444
Once that's done, we can start using Leaf Redis in our Leaf application. Just like any other database, we need to initialize a connection to Redis before we can start using it.
4545

46-
```php
46+
```php:no-line-numbers
4747
redis()->connect();
4848
```
4949

@@ -53,7 +53,26 @@ This will initialize a new Redis connection. From there, you can start storing a
5353

5454
If you're using Leaf MVC, you can add on some extra features to your setup. Leaf Redis comes with a few commands that you can attach to your Aloe CLI. You can do this by heading over to the `app/console/Commands.php` file in your Leaf MVC app and adding the following line to the return array.
5555

56-
```php
56+
::: code-group
57+
58+
```php [Leaf MVC 3.8 and above]
59+
/*
60+
|--------------------------------------------------------------------------
61+
| Load Leaf configuration
62+
|--------------------------------------------------------------------------
63+
|
64+
| Leaf MVC allows you to customize Leaf and it's modules using
65+
| configuration files defined in the config folder. This line
66+
| loads the configuration files and makes them available to
67+
| your application.
68+
|
69+
*/
70+
Leaf\Core::loadConsole([
71+
Leaf\Redis::commands() // [!code ++]
72+
]);
73+
```
74+
75+
```php [Leaf MVC 3.7 and below]
5776
<?php
5877

5978
namespace App\Console;
@@ -71,15 +90,17 @@ class Commands
7190
{
7291
$console->register([
7392
ExampleCommand::class,
74-
\Leaf\Redis::commands() // [!code ++]
93+
Leaf\Redis::commands() // [!code ++]
7594
]);
7695
}
7796
}
7897
```
7998

99+
:::
100+
80101
Once you've done that, you should have access to a bunch of new commands from Leaf Redis. The available commands are:
81102

82-
```bash
103+
```bash:no-line-numbers
83104
redis
84105
redis:install Create leaf redis config and .env variables
85106
redis:server Start redis server
@@ -212,15 +233,15 @@ redis()->connect([
212233

213234
You can check if your Redis connection is working by using the `ping()` method. The `ping()` method returns a string with the message "PONG" if the connection is successful.
214235

215-
```php
236+
```php:no-line-numbers
216237
echo redis()->ping();
217238
```
218239

219240
## Setting values
220241

221242
You can set values in Redis using the `set()` method. The `set()` method takes in a key and a value.
222243

223-
```php
244+
```php:no-line-numbers
224245
redis()->set('name', 'Michael');
225246
```
226247

src/docs/frontend/blade.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Blade is a templating engine included with Laravel that helps you create dynamic
1010

1111
Leaf Blade is a port of the [jenssegers/blade](https://github.com/jenssegers/blade) package that allows you to use blade templates in your Leaf PHP projects.
1212

13+
<!-- Leaf Blade is an adaptation of the original Blade package, which provides a powerful engine that is familiar to most PHP developers. While similar, Leaf Blade has some differences from the original Blade package, so be sure to keep this documentation handy. -->
14+
1315
::: details New to Blade?
1416

1517
This video by The Net Ninja will help you get started with blade.
@@ -27,7 +29,7 @@ This video by The Net Ninja will help you get started with blade.
2729

2830
::: info Blade + Leaf MVC
2931

30-
Blade comes with Leaf MVC out of the box, fully configured and ready to use. However, if you're using Leaf Core, you'll need to set up Blade yourself.
32+
Blade comes with Leaf MVC out of the box, fully configured and ready to use, so you can skip this section if you're using Leaf MVC.
3133

3234
:::
3335

@@ -85,7 +87,7 @@ Blade views are a pretty sweet mixture of HTML, PHP, and clean syntax. You can c
8587

8688
:::
8789

88-
This should look pretty familiar if you know HTML (of course you do). The only difference is the `{{ $name }}` part. This is Blade's way of creating a variable in your view. When you render this view, Blade will allow you pass in a variable called `$name` and it will be displayed in place of `{{ $name }}`. Let's see how you can render this view.
90+
This should look pretty familiar if you know HTML (of course you do). The only difference is the <span v-pre>`{{ $name }}`</span> part. This is Blade's way of creating a variable in your view. When you render this view, Blade will allow you pass in a variable called `$name` and it will be displayed in place of <span v-pre>`{{ $name }}`</span>. Let's see how you can render this view.
8991

9092
## Rendering Blade Views
9193

@@ -97,6 +99,47 @@ echo app()->blade()->render('hello', ['name' => 'Michael']);
9799

98100
This will render the `hello.blade.php` view and pass in a variable called `name` with the value `Michael`. When you open the view in your browser, you should see a big "Hello, Michael" on your screen.
99101

102+
<!-- ## Directives included in Leaf Blade
103+
104+
As mentioned earlier, Leaf Blade is an adaptation of the original Blade package, so it includes some directives that are not available in the original Blade package. Here are some of the directives included in Leaf Blade:
105+
106+
### `@csrf`
107+
108+
The `@csrf` directive generates a hidden CSRF token field for forms. This is useful when you want to include a CSRF token in your form.
109+
110+
```blade:no-line-numbers
111+
<form method="POST">
112+
@csrf
113+
...
114+
</form>
115+
```
116+
117+
### `@method`
118+
119+
The `@method` directive generates a hidden input field with the value of the method you specify. This is useful when you want to use methods other than `GET` and `POST` in your forms.
120+
121+
```blade:no-line-numbers
122+
<form method="POST">
123+
@method('PUT')
124+
...
125+
</form>
126+
127+
<form method="POST">
128+
@method('DELETE')
129+
...
130+
</form>
131+
```
132+
133+
### `@submit`
134+
135+
The `@submit` directive allows you to wrap an item with a form that submits when the item is clicked. This is useful when you want to redirect to a post route when an item is clicked.
136+
137+
```blade:no-line-numbers
138+
@submit('DELETE', '/posts/1')
139+
<button>Delete</button>
140+
@endsubmit
141+
``` -->
142+
100143
## Extending Blade Views
101144

102145
Blade allows you to define custom directives using the `directive()` method. When the Blade compiler encounters the custom directive, it will call the provided callback with the expression that the directive contains. The callback is free to return the value of its contents however you like:

src/docs/mvc/commands.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class CachePurgeCommand extends Command
8282
}
8383
```
8484

85-
You can register this component by heading over to the `app/console/commands.php` file and adding the command to the `register()` method.
85+
If you are using Leaf MVC v3.8 and above, the command is automatically loaded by Leaf MVC. If you are using Leaf MVC v3.7 and below, you will need to register the command in the `app/console/Commands.php` file.n
8686

8787
```php
8888
<?php

src/docs/mvc/console.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ These commands handle your frontend setup, building, and serving.
238238
This is a list of every command available in Aloe. To view this list from your terminal, run `php leaf list`.
239239

240240
```bash:no-line-numbers
241-
Leaf MVC v3.5.0
241+
Leaf MVC v3.8.0
242242
243243
Usage:
244244
command [options] [arguments]
@@ -253,16 +253,19 @@ Options:
253253
254254
Available commands:
255255
completion Dump the shell completion script
256-
example example command's description
257256
help Display help for a command
258257
interact Interact with your application
258+
link Create a symbolic link for the storage directory
259259
list List commands
260260
serve Start the leaf development server
261261
app
262262
app:down Place app in maintainance mode
263263
app:up Remove app from maintainance mode
264264
auth
265265
auth:scaffold Scaffold basic app authentication
266+
config
267+
config:lib Setup Leaf MVC to use external libraries
268+
config:mail Install leaf mail and setup mail config
266269
d
267270
d:command Delete a console command
268271
d:controller Delete a controller
@@ -286,12 +289,13 @@ Available commands:
286289
g:factory Create a new model factory
287290
g:helper Create a new helper class
288291
g:mailer Create a new mailer
292+
g:middleware Create a new application middleware
289293
g:migration Create a new migration file
290294
g:model Create a new model class
291295
g:seed Create a new seed file
292296
g:template Create a new view file
293-
mail
294-
mail:setup Install leaf mail and setup mail config
297+
key
298+
key:generate Run your frontend dev server
295299
view
296300
view:build Run your frontend dev server
297301
view:dev [view:serve] Run your frontend dev server

0 commit comments

Comments
 (0)