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
+33-8Lines changed: 33 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ Although you can write raw queries using the `query()` method, there's no fun in
6
6
7
7
This is something you would usually want to do outside of your application, but there are a few rare cases where you might want to create a database from within your application. Leaf DB provides a `create()` method that allows you to do just that.
8
8
9
-
```php
9
+
```php:no-line-numbers
10
10
db()->create('dbname')->execute();
11
11
```
12
12
@@ -26,7 +26,7 @@ db()
26
26
27
27
Dropping a database is the opposite of creating one. It deletes the database and all its contents. Leaf DB provides a `drop()` method that allows you to do this.
28
28
29
-
```php
29
+
```php:no-line-numbers
30
30
db()->drop('dbname')->execute();
31
31
```
32
32
@@ -40,13 +40,13 @@ This method needs the name of the table you want to add data to, like "users", a
Note that this may not work correctly if your database uses non-auto-incrementing IDs like UUIDs or ULIDs.
93
+
92
94
## Reading data from a database
93
95
94
96
Reading from a database means retrieving data stored in a table. Leaf DB provides a `select()` method that allows you to build a query to retrieve data from a table. The `select()` method takes the name of the table you want to read from as its argument.
95
97
96
-
```php
98
+
```php:no-line-numbers
97
99
db()->select('users')->all();
98
100
```
99
101
100
102
This will return all the rows in the users table. You can also specify the columns you want to return by passing them as the second argument to the `select()` method.
101
103
102
-
```php
104
+
```php:no-line-numbers
103
105
db()->select('users', 'name, created_at')->all();
104
106
```
105
107
@@ -172,7 +174,7 @@ db()
172
174
173
175
Almost every database table has an `id` column that uniquely identifies each row. Leaf DB provides a `find()` method that allows you to retrieve a row by its `id`.
174
176
175
-
```php
177
+
```php:no-line-numbers
176
178
db()->select('users')->find(1);
177
179
```
178
180
@@ -209,7 +211,7 @@ Deleting data from a database works by finding the data you want to delete and t
209
211
210
212
Here's an example:
211
213
212
-
```php
214
+
```php:no-line-numbers
213
215
db()->delete('users')->execute(); // careful now 🙂
214
216
```
215
217
@@ -259,6 +261,10 @@ if ($success) {
259
261
260
262
This is useful especially when you have a set of queries that rely on third party influence.
261
263
264
+
::: warning Rollback not working
265
+
Transactions will only work correctly if your queries use Leaf DB. This is because your queries need to use the same database connection to be able to be rolled back. This means you can't use transactions with your Leaf MVC models at the moment, but this may change in the future.
266
+
:::
267
+
262
268
## Hiding columns from results
263
269
264
270
Sometimes you might want to hide certain columns from the results of a query. For instance, you might want to hide the password column from the results of a query on the users table. Leaf DB provides a `hide()` method that allows you to do this.
@@ -342,6 +348,25 @@ db()
342
348
->all();
343
349
```
344
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
+
345
370
## Error Handling
346
371
347
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:
Headers are a way for your server to send additional information along with your request. This information can be anything from the type of content you're sending back, to the status code of your response, to the type of server you're using.
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