Skip to content

Commit 4a5f8fa

Browse files
committed
feat: update controllers
1 parent 2584f86 commit 4a5f8fa

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/docs/mvc/controllers.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ You can have as many methods as you want in your controller. Each method should
5454

5555
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:
5656

57-
```php
57+
```php:no-line-numbers
5858
app()->get('/users', 'UsersController@index');
5959
```
6060

@@ -83,7 +83,7 @@ You can find the views documentation [here](/docs/frontend/)
8383

8484
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:
8585

86-
```php
86+
```php:no-line-numbers
8787
app()->get('/users', ['middleware' => 'auth', 'UsersController@index']);
8888
```
8989

@@ -95,7 +95,7 @@ Leaf makes it super easy to set up routes for common actions like creating, read
9595

9696
To get started, you can generate a resource controller using the Aloe CLI:
9797

98-
```bash
98+
```bash:no-line-numbers
9999
php leaf g:controller photos --resource
100100
```
101101

@@ -146,7 +146,7 @@ class PhotosController extends Controller {
146146

147147
You can then define your routes like this:
148148

149-
```php
149+
```php:no-line-numbers
150150
app()->resource('/photos', 'PhotosController');
151151
```
152152

@@ -164,33 +164,33 @@ This will automatically set up all the routes you need for CRUD operations on th
164164

165165
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:
166166

167-
```bash
167+
```bash:no-line-numbers
168168
php leaf g:controller photos --api
169169
```
170170

171171
You can load the controller in your routes like this:
172172

173-
```php
173+
```php:no-line-numbers
174174
app()->apiResource('/photos', 'PhotosController');
175175
```
176176

177177
## Aloe Console Helper
178178

179179
Allow has a few more shortcuts you can incorporate into your controller generation:
180180

181-
```bash
181+
```bash:no-line-numbers
182182
php leaf g:controller <ControllerName> -m
183183
```
184184

185185
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.
186186

187-
```bash
187+
```bash:no-line-numbers
188188
php leaf g:controller <ControllerName> -t
189189
```
190190

191191
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.
192192

193-
```bash
193+
```bash:no-line-numbers
194194
php leaf g:controller <ControllerName> -a
195195
```
196196

0 commit comments

Comments
 (0)