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
Numerous web applications offer their users a means to authenticate and access the application by "logging in." Adding this functionality to web applications can be a challenging and potentially dangerous task.
6
10
7
11
Leaf provides a lightweight but very powerful authentication system to handle all the complexities of authentication in a few lines of code. We understand that authentication is a critical part of your application, so we've made it as simple and secure as possible.
8
12
9
-
::: warning Docs version
10
-
This documentation covers Auth v3 and above. If you're using an older version, you can check the documentation [hosted here](https://v3.leafphp.dev/modules/auth/).
You can think of your application's environment as a set of configurations that define how your application behaves in different situations. For example, you may run a local database when developing your app, but will want your app to connect to a remote database when it's in production.
We've crafted a specialized guide for config in Leaf MVC. While it's similar to the basic config in Leaf, it's more detailed and tailored for Leaf MVC.
Common environments include `development`, `testing`, and `production`. Leaf already has some pre-programmed bahaviours for these environments, but you can also create your own custom environments. One way to do this is to use environment variables.
[Inertia](https://inertiajs.com/) is a new approach to building classic server-driven web apps. It allows you to create fully client-side rendered, single-page apps, without the complexity that comes with modern SPAs.
4
10
5
11
In short, Inertia let's you use your favourite frontend framework together with Leaf, reaping the benefits of both. While it's still more popular to build completely separate frontend and backends, combining them lets you have your code in one place.
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.
143
149
144
-
### 1. Setting up Vite
150
+
### <TutorialNumbernumber="1" /> Setting up Vite
145
151
146
152
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).
147
153
@@ -150,7 +156,7 @@ npm i -D vite @leafphp/vite-plugin
150
156
leaf install vite
151
157
```
152
158
153
-
### 2. Vite Config
159
+
### <TutorialNumbernumber="2" /> Vite Config
154
160
155
161
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.
156
162
@@ -176,7 +182,7 @@ leaf({
176
182
}),
177
183
```
178
184
179
-
### 3. Setting up Inertia
185
+
### <TutorialNumbernumber="3" /> Setting up Inertia
180
186
181
187
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:
182
188
@@ -215,7 +221,7 @@ export default defineConfig({
215
221
});
216
222
```
217
223
218
-
### 4. Setting up your base JavaScript file
224
+
### <TutorialNumbernumber="4" /> Setting up your base JavaScript file
219
225
220
226
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:
221
227
@@ -249,7 +255,7 @@ setup({ el, App, props }) {
249
255
},
250
256
```
251
257
252
-
### 5. Setting up your base PHP file
258
+
### <TutorialNumbernumber="5" /> Setting up your base PHP file
253
259
254
260
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.
255
261
@@ -305,7 +311,7 @@ This might look pretty ugly, but you'll never have to touch this file again. You
305
311
leaf view:install --inertia
306
312
```
307
313
308
-
### 6. Setting up your frontend framework
314
+
### <TutorialNumbernumber="6" /> Setting up your frontend framework
309
315
310
316
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:
Copy file name to clipboardExpand all lines: src/docs/frontend/tailwind.md
+18-17Lines changed: 18 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,14 @@
1
1
# Tailwind + Leaf
2
2
3
-
Tailwind is a utility-first CSS framework that provides a set of utility classes to help you build your UI. Leaf has first-class support for Tailwind CSS, and it's the recommended way to style your Inertia apps. This guide will show you how to set up Tailwind CSS in your Leaf project with minimal configuration.
Tailwind 4 has been released, and it unfortunately breaks the current Leaf CLI installation. Leaf MVC works fine with Tailwind 4, but we are working on a fix for the CLI. For now, you can install Tailwind manually if you are not using Leaf MVC.
9
+
Tailwind is a utility-first CSS framework that provides a set of utility classes to help you build your UI. Leaf has first-class support for Tailwind CSS, and it's the recommended way to style your Inertia apps. This guide will show you how to set up Tailwind CSS in your Leaf project with minimal configuration.
10
10
11
-
:::
11
+
## Using the CLI
12
12
13
13
You can set up Tailwind CSS in your Leaf MVC project using the php leaf console. To do this, run the following command:
Copy file name to clipboardExpand all lines: src/docs/http/cookies.md
+10-6Lines changed: 10 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,21 +68,25 @@ The `set()` method allows you to set cookies with more advanced options like exp
68
68
69
69
## Reading Cookies
70
70
71
-
When you send cookies to the client, they are stored in your users' browser and automatically sent back to your app on every request. You can read these cookies using the `get()` method.
71
+
When you send cookies to the client, they are stored in your users' browsers and automatically sent back to your app on every request. You can read these cookies using the `cookies()` method on the incoming request.
72
72
73
73
```php:no-line-numbers
74
-
$name = cookie()->get('name');
74
+
$name = request()->cookies('name');
75
+
76
+
// You can also get multiple cookies at once
77
+
$cookies = request()->cookies(['name', 'age']);
78
+
// $cookies['name'] and $cookies['age']
75
79
```
76
80
77
-
This method takes in the cookie name and returns the cookie value. If the cookie doesn't exist, it returns `null`.
81
+
if a cookie doesn't exist, the `cookies()` method will return `null` for that cookie.
78
82
79
-
You can also get all cookies at once using the `all()`method.
83
+
You can also get all cookies at once by calling `cookies()`without any parameters.
80
84
81
85
```php:no-line-numbers
82
-
$cookies = cookie()->all();
86
+
$cookies = request()->cookies();
83
87
```
84
88
85
-
This method returns an array of all cookies sent to your app. Be careful when using this method as it can return a lot of data.
89
+
This method returns an array of all cookies sent to your app. Be careful when using this method as it can return a lot of data, including cookies that you may not need.
From Wikipedia, Cross-origin resource sharing (CORS) is a mechanism that allows restricted resources on a web page to be accessed from another domain outside the domain from which the first resource was served.
@@ -21,6 +22,34 @@ Cross-Origin Resource Sharing or CORS is a mechanism that allows browsers to req
21
22
22
23
Since CORS is a common pain point for web developers, Leaf provides a first-party integration that takes care of all the heavy lifting for you.
0 commit comments