route
function:array
, you can listen for multiple HTTP methods on the same handler:?
as sufix:<handler>
placeholder you saw is where you can put the route logic and it can be contained on the following:$params
variable:path/to/files
matching the HTTP URI according to the table below:/users
/api/users/index.php
/users/create
/api/users/create.php
/users
/api/users/store.php
/users/{id}
/api/users/show.php
/users/{id}/edit
/api/users/edit.php
/users/{id}
/api/users/update.php
/users/{id}
/api/users/destroy.php
index.get.php
/
index.post.php
/
foo.get.php
/foo
bar/index.get.php
/bar
foo.bar.get.php
/foo/bar
foo/bar.get.php
/foo/bar
foo/bar/index.get.php
/foo/bar
{
and }
are valid chars in a filename, route parameters should work as well, but you can define required parameters prefixing with $
and optional parameters using @
:foo.{slug}.get.php
/foo/{slug}
foo.$slug.get.php
/foo/{slug}
foo.options.php
/foo
foo.x-custom.php
/foo
FooController
constructor for each request even if it's not a request to /foo
.Closure
:FooController
is called only when there is a match for route /foo
.
One downside is that now you have to explicitly manage path parameters, on the other hand is a best practice to do so.
It is a good time to validate parameters, convert plain string parameters to meaningful types on your domain or resolve dependencies.array
:echo
or print
so use carefully, it's not a encoder, it's an output-er.header
function at Response
namespace: