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/database/builder.md
+19Lines changed: 19 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -348,6 +348,25 @@ db()
348
348
->all();
349
349
```
350
350
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
+
351
370
## Error Handling
352
371
353
372
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.
Copy file name to clipboardExpand all lines: src/docs/database/redis.md
+27-6Lines changed: 27 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,7 +43,7 @@ composer require leafs/redis
43
43
44
44
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.
45
45
46
-
```php
46
+
```php:no-line-numbers
47
47
redis()->connect();
48
48
```
49
49
@@ -53,7 +53,26 @@ This will initialize a new Redis connection. From there, you can start storing a
53
53
54
54
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.
| 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]
57
76
<?php
58
77
59
78
namespace App\Console;
@@ -71,15 +90,17 @@ class Commands
71
90
{
72
91
$console->register([
73
92
ExampleCommand::class,
74
-
\Leaf\Redis::commands() // [!code ++]
93
+
Leaf\Redis::commands() // [!code ++]
75
94
]);
76
95
}
77
96
}
78
97
```
79
98
99
+
:::
100
+
80
101
Once you've done that, you should have access to a bunch of new commands from Leaf Redis. The available commands are:
81
102
82
-
```bash
103
+
```bash:no-line-numbers
83
104
redis
84
105
redis:install Create leaf redis config and .env variables
85
106
redis:server Start redis server
@@ -212,15 +233,15 @@ redis()->connect([
212
233
213
234
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.
214
235
215
-
```php
236
+
```php:no-line-numbers
216
237
echo redis()->ping();
217
238
```
218
239
219
240
## Setting values
220
241
221
242
You can set values in Redis using the `set()` method. The `set()` method takes in a key and a value.
Copy file name to clipboardExpand all lines: src/docs/frontend/blade.md
+45-2Lines changed: 45 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,8 @@ Blade is a templating engine included with Laravel that helps you create dynamic
10
10
11
11
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.
12
12
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
+
13
15
::: details New to Blade?
14
16
15
17
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.
27
29
28
30
::: info Blade + Leaf MVC
29
31
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.
31
33
32
34
:::
33
35
@@ -85,7 +87,7 @@ Blade views are a pretty sweet mixture of HTML, PHP, and clean syntax. You can c
85
87
86
88
:::
87
89
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 <spanv-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 <spanv-pre>`{{ $name }}`</span>. Let's see how you can render this view.
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.
99
101
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
+
100
143
## Extending Blade Views
101
144
102
145
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:
Copy file name to clipboardExpand all lines: src/docs/mvc/commands.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -82,7 +82,7 @@ class CachePurgeCommand extends Command
82
82
}
83
83
```
84
84
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
0 commit comments