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/mvc/controllers.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,7 +54,7 @@ You can have as many methods as you want in your controller. Each method should
54
54
55
55
After defining a controller with the methods that you will use to handle your routes, you need to tell Leaf when to load a controller and which method to call. You can do this by defining a route in your `app/routes/` directory, and then calling the method in the controller that should handle the route. Here's an example:
56
56
57
-
```php
57
+
```php:no-line-numbers
58
58
app()->get('/users', 'UsersController@index');
59
59
```
60
60
@@ -83,7 +83,7 @@ You can find the views documentation [here](/docs/frontend/)
83
83
84
84
When you're building web apps, sometimes you need extra functionality when someone visits a route. For example, maybe only logged-in users should be able to see certain pages. To manage this, Leaf lets you add route parameters like middleware to your routes. This feature also works for controllers and uses the same syntax as function route handlers. Here's an example:
@@ -95,7 +95,7 @@ Leaf makes it super easy to set up routes for common actions like creating, read
95
95
96
96
To get started, you can generate a resource controller using the Aloe CLI:
97
97
98
-
```bash
98
+
```bash:no-line-numbers
99
99
php leaf g:controller photos --resource
100
100
```
101
101
@@ -146,7 +146,7 @@ class PhotosController extends Controller {
146
146
147
147
You can then define your routes like this:
148
148
149
-
```php
149
+
```php:no-line-numbers
150
150
app()->resource('/photos', 'PhotosController');
151
151
```
152
152
@@ -164,33 +164,33 @@ This will automatically set up all the routes you need for CRUD operations on th
164
164
165
165
API resource controllers are similar to resource controllers, but they return JSON responses instead of HTML which means that the `create` and `edit` methods are not included. You can generate an API resource controller using the Aloe CLI:
166
166
167
-
```bash
167
+
```bash:no-line-numbers
168
168
php leaf g:controller photos --api
169
169
```
170
170
171
171
You can load the controller in your routes like this:
Allow has a few more shortcuts you can incorporate into your controller generation:
180
180
181
-
```bash
181
+
```bash:no-line-numbers
182
182
php leaf g:controller <ControllerName> -m
183
183
```
184
184
185
185
This command will generate your controller together with a model that corresponds to the controller name. The model will be generated in the `app/models` directory.
186
186
187
-
```bash
187
+
```bash:no-line-numbers
188
188
php leaf g:controller <ControllerName> -t
189
189
```
190
190
191
191
The `-t` flag will generate a controller with a frontend template that corresponds to the controller name. The template will be generated in the `app/views` directory.
0 commit comments