Skip to content

Commit 0661b18

Browse files
committed
feat: add learning paths
1 parent 614de03 commit 0661b18

File tree

8 files changed

+758
-71
lines changed

8 files changed

+758
-71
lines changed

.vitepress/config/sidebar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ const sidebar = [
149149
// collapsible: true,
150150
// collapsed: true,
151151
items: [
152-
{ text: 'Leaf + MVC', link: '/docs/mvc/' },
152+
// { text: 'Leaf + MVC', link: '/docs/mvc/' },
153153
{ text: 'Leaf MVC v4', link: '/docs/mvc/mvc4' },
154154
{ text: 'Controllers', link: '/docs/mvc/controllers' },
155155
// { text: 'Views', link: '/docs/frontend/mvc' },

.vitepress/theme/components/shared/Paperplane.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
alt="Paperplane" width="457" height="336">
55

66
<p class="mt-4 mb-2 text-xs">
7+
<i>From the creators of Leaf PHP - </i>
78
Build your next big idea Supafast without the hassle of setting up repetitive tasks.
89
</p>
910

src/docs/auth/mvc.md

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,175 @@
1+
---
2+
next: false
3+
prev: false
4+
---
5+
16
# Auth in Leaf MVC
7+
8+
## What to read next
9+
10+
Now that you have built a simple pre-launch page, the next step is to get you familiar with the basics of building a full-stack application with Leaf. So you can build and launch your next big idea *fast*.
11+
12+
<ul
13+
class="!mt-10 grid grid-cols-1 gap-x-16 gap-y-8 xl:grid-cols-2 xl:gap-y-10 !pl-0"
14+
>
15+
<li class="relative flex items-start">
16+
<div
17+
class="w-16 h-16 p-[0.1875rem] rounded-full ring-1 ring-slate-900/10 shadow overflow-hidden flex-none dark:ring-white/50"
18+
>
19+
<div
20+
class="bg-[length:150%] rounded-full h-full bg-center bg-no-repeat bg-pink-100 dark:bg-pink-200"
21+
style="
22+
background-image: url(/images/illustrations/Feature-Flags-5.svg);
23+
"
24+
></div>
25+
</div>
26+
<div class="peer group flex-auto ml-6">
27+
<h3
28+
class="mb-2 font-semibold !text-slate-900 dark:!text-slate-200 !m-0"
29+
>
30+
<a
31+
class="before:absolute before:-inset-3 before:rounded-2xl !text-inherit sm:before:-inset-4 !no-underline"
32+
href="/docs/routing/"
33+
>Routing<svg
34+
viewBox="0 0 3 6"
35+
class="ml-3 w-auto h-1.5 overflow-visible inline -mt-px text-slate-400 opacity-0 group-hover:opacity-100 group-focus-within:opacity-100"
36+
>
37+
<path
38+
d="M0 0L3 3L0 6"
39+
fill="none"
40+
stroke-width="2"
41+
stroke="currentColor"
42+
stroke-linecap="round"
43+
stroke-linejoin="round"
44+
></path></svg
45+
></a>
46+
</h3>
47+
<p class="text-[var(--vp-c-text-2)] !m-0 text-sm">
48+
Learn more about routing in Leaf MVC, dynamic routes, middleware and more.
49+
</p>
50+
</div>
51+
<div
52+
class="absolute -z-10 -inset-3 rounded-2xl bg-slate-50 dark:bg-[var(--vp-c-bg-alt)] opacity-0 peer-hover:opacity-100 sm:-inset-4"
53+
></div>
54+
</li>
55+
<li class="relative flex items-start">
56+
<div
57+
class="w-16 h-16 p-[0.1875rem] rounded-full ring-1 ring-slate-900/10 shadow overflow-hidden flex-none dark:ring-white/50"
58+
>
59+
<div
60+
class="bg-[length:350%] rounded-full h-full bg-green-100 dark:bg-green-200 bg-center bg-no-repeat"
61+
style="
62+
background-image: url(/images/illustrations/Heading-2.svg);
63+
"
64+
></div>
65+
</div>
66+
<div class="peer group flex-auto ml-6">
67+
<h3
68+
class="mb-2 font-semibold !text-slate-900 dark:!text-slate-200 !m-0"
69+
>
70+
<a
71+
class="before:absolute before:-inset-3 before:rounded-2xl !text-inherit sm:before:-inset-4 !no-underline"
72+
href="/docs/http/request"
73+
>Handling Requests<svg
74+
viewBox="0 0 3 6"
75+
class="ml-3 w-auto h-1.5 overflow-visible inline -mt-px text-slate-400 opacity-0 group-hover:opacity-100 group-focus-within:opacity-100"
76+
>
77+
<path
78+
d="M0 0L3 3L0 6"
79+
fill="none"
80+
stroke-width="2"
81+
stroke="currentColor"
82+
stroke-linecap="round"
83+
stroke-linejoin="round"
84+
></path></svg
85+
></a>
86+
</h3>
87+
<p class="text-[var(--vp-c-text-2)] !m-0 text-sm">
88+
Learn how to process incoming requests, handle form submissions, and more.
89+
</p>
90+
</div>
91+
<div
92+
class="absolute -z-10 -inset-3 rounded-2xl bg-slate-50 dark:bg-[var(--vp-c-bg-alt)] opacity-0 peer-hover:opacity-100 sm:-inset-4"
93+
></div>
94+
</li>
95+
<li class="relative flex items-start">
96+
<div
97+
class="w-16 h-16 p-[0.1875rem] rounded-full ring-1 ring-slate-900/10 shadow overflow-hidden flex-none dark:ring-white/50"
98+
>
99+
<div
100+
class="bg-[length:120%] rounded-full h-full bg-purple-100 dark:bg-purple-200 bg-center bg-no-repeat"
101+
style="
102+
background-image: url(/images/illustrations/db.svg);
103+
"
104+
></div>
105+
</div>
106+
<div class="peer group flex-auto ml-6">
107+
<h3
108+
class="mb-2 font-semibold !text-slate-900 dark:!text-slate-200 !m-0"
109+
>
110+
<a
111+
class="before:absolute before:-inset-3 before:rounded-2xl !text-inherit sm:before:-inset-4 !no-underline"
112+
href="/docs/database/"
113+
>Using Databases<svg
114+
viewBox="0 0 3 6"
115+
class="ml-3 w-auto h-1.5 overflow-visible inline -mt-px text-slate-400 opacity-0 group-hover:opacity-100 group-focus-within:opacity-100"
116+
>
117+
<path
118+
d="M0 0L3 3L0 6"
119+
fill="none"
120+
stroke-width="2"
121+
stroke="currentColor"
122+
stroke-linecap="round"
123+
stroke-linejoin="round"
124+
></path></svg
125+
></a>
126+
</h3>
127+
<p class="text-[var(--vp-c-text-2)] !m-0 text-sm">
128+
Learn how to build queries, build relationships, and interact with your database programmatically.
129+
</p>
130+
</div>
131+
<div
132+
class="absolute -z-10 -inset-3 rounded-2xl bg-slate-50 dark:bg-[var(--vp-c-bg-alt)] opacity-0 peer-hover:opacity-100 sm:-inset-4"
133+
></div>
134+
</li>
135+
<li class="relative flex items-start">
136+
<div
137+
class="w-16 h-16 p-[0.1875rem] rounded-full ring-1 ring-slate-900/10 shadow overflow-hidden flex-none dark:ring-white/50"
138+
>
139+
<div
140+
class="bg-[length:400%] rounded-full h-full bg-yellow-100 dark:bg-yellow-200 bg-center bg-no-repeat"
141+
style="
142+
background-image: url(/images/illustrations/Stats-2.svg);
143+
"
144+
></div>
145+
</div>
146+
<div class="peer group flex-auto ml-6">
147+
<h3
148+
class="mb-2 font-semibold !text-slate-900 dark:!text-slate-200 !m-0"
149+
>
150+
<a
151+
class="before:absolute before:-inset-3 before:rounded-2xl !text-inherit sm:before:-inset-4 !no-underline"
152+
href="/docs/frontend/"
153+
>Frontend<svg
154+
viewBox="0 0 3 6"
155+
class="ml-3 w-auto h-1.5 overflow-visible inline -mt-px text-slate-400 opacity-0 group-hover:opacity-100 group-focus-within:opacity-100"
156+
>
157+
<path
158+
d="M0 0L3 3L0 6"
159+
fill="none"
160+
stroke-width="2"
161+
stroke="currentColor"
162+
stroke-linecap="round"
163+
stroke-linejoin="round"
164+
></path></svg
165+
></a>
166+
</h3>
167+
<p class="text-[var(--vp-c-text-2)] !m-0 text-sm">
168+
Learn about SSR, SPA, and how to use Leaf with your favorite frontend framework.
169+
</p>
170+
</div>
171+
<div
172+
class="absolute -z-10 -inset-3 rounded-2xl bg-slate-50 dark:bg-[var(--vp-c-bg-alt)] opacity-0 peer-hover:opacity-100 sm:-inset-4"
173+
></div>
174+
</li>
175+
</ul>

src/docs/routing/index.md

Lines changed: 15 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ You can add a route that handles only `POST` HTTP requests with the Leaf router'
7575
- The route handler
7676

7777
```php
78-
app()->post('/users/add', function () use($request) {
79-
$user = $request->get('user');
78+
app()->post('/users/add', function () {
79+
$user = request()->get('user');
8080
// create a new user
8181
});
8282
```
@@ -134,6 +134,19 @@ app()->match('GET|POST', '/users', function () {
134134
});
135135
```
136136

137+
## Create a view route
138+
139+
If your route needs to return a template without any logic, you can use the `view()` method. This method accepts two arguments:
140+
141+
- The route pattern
142+
- The view file to render
143+
144+
```php
145+
app()->view('/home', 'home');
146+
```
147+
148+
The `view()` method will look for the view file using whatever view engine you have set up in your app. For instance, if you have blade setup, it will look for a file called `home.blade.php`. The template location also depends on your view engine setup.
149+
137150
## Running your routes
138151

139152
After defining all the routes you application needs, you need to start the router to listen for incoming requests. You can do this by calling the `run()` method.
@@ -214,62 +227,3 @@ If your route has a name, you can navigate to it by passing the route name in an
214227
```php:no-line-numbers
215228
response()->redirect(['home']);
216229
```
217-
218-
## View routes <Badge text="NEW" type="tip" />
219-
220-
If your route needs to return a template without any logic, you can use the `view()` method. This method accepts two arguments:
221-
222-
- The route pattern
223-
- The view file to render
224-
225-
```php:no-line-numbers
226-
app()->view('/home', 'home');
227-
```
228-
229-
The `view()` method will look for the view file using whatever view engine you have set up in your app. For instance, if you have blade setup, it will look for a file called `home.blade.php`. The template location also depends on your view engine setup. If you are using Leaf MVC, it will look for the file in the `app/views` folder and will use blade as the view engine.
230-
231-
## Routing in Leaf MVC
232-
233-
Leaf MVC comes with an `app/routes` folder that organizes all your route files. The `app/routes/index.php` file is the entry point for all your routes and contains the setup for 404s, maintenance mode and other global route settings.
234-
235-
To create a new route, add a file that starts with `_` to the `app/routes` folder. For example, you can create a file called `app/routes/_auth.php` and add all your authentication routes to it. This file will be automatically loaded by Leaf MVC, and all the routes in it will be available in your app.
236-
237-
If you don't want a file in the `app/routes` folder to be automatically loaded, create a file that doesn't start with `_`. For example, you can create a file called `app/routes/custom.php` and add all your routes to it. This file will **NOT** be automatically loaded by Leaf MVC, and you'll have to load it manually.
238-
239-
### Controllers
240-
241-
Beyond that, Leaf MVC uses controllers to handle routes instead of closures. This means you can create a controller for each route and handle the route logic in the controller. You can learn more about controllers in the [Controller section.](/docs/mvc/controllers)
242-
243-
### Updating Error Screens
244-
245-
If you need to set up custom error responses, you can do so in the `app/routes/index.php` file. We have loaded examples for 404 and 500 error pages. You can customize these to your liking.
246-
247-
```php
248-
/*
249-
|--------------------------------------------------------------------------
250-
| Set up 404 handler
251-
|--------------------------------------------------------------------------
252-
|
253-
| Leaf provides a default 404 page, but you can also create your
254-
| own 404 handler by calling app()->set404(). Whatever function
255-
| you set will be called when a 404 error is encountered
256-
|
257-
*/
258-
app()->set404(function () {
259-
response()->json('Resource not found', 404, true);
260-
});
261-
262-
/*
263-
|--------------------------------------------------------------------------
264-
| Set up 500 handler
265-
|--------------------------------------------------------------------------
266-
|
267-
| Leaf provides a default 500 page, but you can create your own error
268-
| 500 handler by calling the setErrorHandler() method. The function
269-
| you set will be called when a 500 error is encountered
270-
|
271-
*/
272-
app()->setErrorHandler(function () {
273-
response()->json('An error occured, our team has been notified', 500, true);
274-
});
275-
```

0 commit comments

Comments
 (0)