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/auth/index.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
@@ -84,7 +84,7 @@ That's all you need to do. Leaf Auth will automatically connect to your database
84
84
85
85
Leaf Auth doesn't give you any structure for your database, with that, you can structure your database in any way you prefer. However, there are some things you should note:
86
86
87
-
1. By default, Leaf Auth assumes that your database primary key is `id`. If you have a database where you are using another field, say `admin_id` as the primary key, you will need to tell Leaf the name of your primary key. You can do this using the `ID_KEY` config:
87
+
1. By default, Leaf Auth assumes that your database primary key is `id`. If you have a database where you are using another field, say `admin_id` as the primary key, you will need to tell Leaf the name of your primary key. You can do this using the `id.key` config:
Copy file name to clipboardExpand all lines: src/docs/auth/login.md
+32-13Lines changed: 32 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,7 @@ $data = auth()->login([
50
50
'password' => 'password'
51
51
]);
52
52
53
-
if($data) {
53
+
if($data) {
54
54
// User is authenticated
55
55
$token = $data->token;
56
56
$user = $data->user;
@@ -70,13 +70,33 @@ Leaf uses token based authentication by default which uses a JWT to authenticate
70
70
auth()->config('session', true);
71
71
```
72
72
73
-
With this, a new login will create a session for the user. If your app requires users to be redirected to a different page after login, you can configure Leaf Auth to do just that:
73
+
With the addition of session auth, `login()` will automatically start a session, but will leave redirects and every other thing to you:
You can also generate JWT tokens for your sessions if you want to:
90
-
91
-
```php:no-line-numbers
92
-
auth()->config('session.jwt', true);
93
-
```
94
-
95
109
## Auth with no password
96
110
97
111
Leaf Auth usually expects a password field to authenticate users. This is necessary because most applications require a password to authenticate users. The field is usually named `password`, however, you can configure Leaf Auth to expect a different field:
By default, the logout method will just end the user's session. If you want to perform a custom operation when a user logs out, you can set a handler for the logout operation:
257
+
If you want to perform a custom operation when a user logs out, you can set a handler for the logout operation:
241
258
242
259
```php
243
260
auth()->config('session.logout', function () {
244
261
// your logout handler
245
262
});
246
263
```
264
+
265
+
This will ignore whatever route is passed into the `logout()` method and rely solely on the function passed into the session.logout config.
Copy file name to clipboardExpand all lines: src/docs/auth/signup.md
+17-13Lines changed: 17 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -80,7 +80,7 @@ $data = auth()->register([
80
80
'password' => 'password'
81
81
]);
82
82
83
-
if($data) {
83
+
if($data) {
84
84
// User is authenticated
85
85
$token = $data->token;
86
86
$user = $data->user;
@@ -107,7 +107,7 @@ $data = auth()->register([
107
107
'password' => 'password'
108
108
]);
109
109
110
-
if(!$data) {
110
+
if(!$data) {
111
111
$error = auth()->errors();
112
112
// ['email' => 'The email already exists']
113
113
}
@@ -158,16 +158,26 @@ Leaf uses token based authentication by default which uses a JWT to authenticate
158
158
auth()->config('session', true);
159
159
```
160
160
161
-
This however won't automatically log in a user after registration meaning no session will be created after a user signs up. If you want to automatically log in a user after registration, you can configure Leaf Auth to do that:
161
+
Switching to session auth does not change the default behaviour of the `register()` method. It won't create a session or do anything fancy by default. If you want to create a session immediately after signing a user up, you can pass true to the `session.register` config:
162
162
163
163
```php:no-line-numbers
164
164
auth()->config('session.register', true);
165
-
```
166
165
167
-
You can also set the URL where your app should redirect users to after registration:
Copy file name to clipboardExpand all lines: src/docs/database/builder.md
+35Lines changed: 35 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -224,6 +224,41 @@ db()
224
224
225
225
This will delete the row in the users table with the `id` of 1.
226
226
227
+
## Database Transactions
228
+
229
+
Database transactions are a way to ...
230
+
Leaf DB allows you to create database transactions using the `transaction()` method. It takes in a callable which is every query you want to perform as part of your transaction.
If anything in the function fails, Leaf will automatically rollback every change that has been made in the database till that point and return `false`. You can get the associated error using the `errors()` method.
247
+
248
+
```php
249
+
$success = db()->transaction(function () {
250
+
...
251
+
});
252
+
253
+
if ($success) {
254
+
// do something
255
+
} else {
256
+
$errors = db()->errors();
257
+
}
258
+
```
259
+
260
+
This is useful especially when you have a set of queries that rely on third party influence.
261
+
227
262
## Hiding columns from results
228
263
229
264
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.
Copy file name to clipboardExpand all lines: src/docs/http/caching.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,10 +32,10 @@ An ETag is a unique identifier for a resource URI. After setting the Etag header
32
32
Setting an ETag with Leaf is very simple. Invoke Leaf’s etag method in your route callback, passing it a unique ID as the first and only argument.
33
33
34
34
```php
35
-
use \Leaf\Http\Headers;
35
+
use Leaf\Http\Cache;
36
36
37
37
app()->get('/', function () {
38
-
Headers::etag('unique-tag');
38
+
Cache::etag('unique-tag');
39
39
40
40
echo 'This will be cached after the initial request!';
41
41
});
@@ -50,11 +50,11 @@ Used in conjunction with the Leaf application’s etag or lastModified methods,
50
50
The expires method accepts one argument: an integer UNIX timestamp, or a string to be parsed with `strtotime()`.
51
51
52
52
```php
53
-
use \Leaf\Http\Headers;
53
+
use Leaf\Http\Cache;
54
54
55
55
app()->get('/', function () {
56
-
Headers::etag('unique-tag');
57
-
Headers::expires('+1 week');
56
+
Cache::etag('unique-tag');
57
+
Cache::expires('+1 week');
58
58
59
59
echo 'This will be cached client-side for one week';
60
60
});
@@ -67,10 +67,10 @@ A Leaf provides built-in support for HTTP caching using the resource’s last mo
67
67
Setting a last modified date with Leaf is very simple. You only need to invoke the Leaf’s lastModified() method in your route callback passing in a UNIX timestamp of the last modification date for the given resource. Be sure the lastModified() method’s timestamp updates along with the resource’s last modification date; otherwise, the browser client will continue serving its outdated cache.
68
68
69
69
```php
70
-
use \Leaf\Http\Headers;
70
+
use Leaf\Http\Cache;
71
71
72
72
app()->get('/', function () {
73
-
Headers::lastModified(1617383991);
73
+
Cache::lastModified(1617383991);
74
74
75
75
echo 'This will be cached after the initial request!';
76
76
});
@@ -81,7 +81,7 @@ app()->get('/', function () {
81
81
There are other cache-related headers that Leaf doesn't provide direct methods for. You can set these headers directly using Leaf's Headers::set() method.
Copy file name to clipboardExpand all lines: src/docs/utils/fetch.md
+23-13Lines changed: 23 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -77,38 +77,48 @@ It gets even simpler when you're making a GET or POST request. Fetch provides so
77
77
GET requests are the most common type of request you'll make when fetching data from an API. Fetch makes it easy to make GET requests using the global `fetch()` function. Here's an example of how you can make a GET request using Fetch:
// data returned is saved in the $data property just like axios
83
83
response()->json($res->data);
84
84
```
85
85
86
-
Every request made using Fetch returns a `FetchResponse` object. This object contains the response data, status code, headers, and more. You can access the response data using the `data` property.
86
+
Or you pass the url directly to the `fetch()` function.
// data returned is saved in the $data property just like axios
92
+
response()->json($res->data);
93
+
```
89
94
90
-
POST requests are used to send data to a server to create or update a resource. You can make POST requests using Fetch by passing an array of data as the second argument to the `fetch()` function. Here's an example:
95
+
## Making Other Requests
96
+
97
+
Fetch works just like the Leaf router, in a sense that every request type has a shortcut method. You can call `get()`, `post()`, `put()`, `patch()`, `delete()` and `options()` to make any kind of request you want.
Once `fetch()` detects that you're passing an array as the second argument, it automatically converts the request to a POST request.
103
-
104
114
## Setting Base URLs
105
115
106
116
Base URLs are useful when you're making requests to the same server or API. One popular use case for base URLs is when you're working with a REST API as it allows you to ignore typing lengthy URLs for every request.
107
117
108
-
You can set a base URL for all your requests using the `baseUrl()` method on the `Fetch` class.
118
+
You can set a base URL for all your requests using the `baseUrl()` method on the `fetch` function.
0 commit comments