Building a view based route
In the preceding recipe, we showed how to build a JSON-based API response in a route with a real view. I will show here just how simple it is in routes to output a View. Typically, I would use a controller but in this case I will not, just to show how you can experiment in a route at different levels.
Getting ready
A base install will be fine for this one.
How to do it…
- Let's add another route for this:
- Then, make a view to handle that route
resources/views/examples/route_view.blade.php
: - And give it a look http://recipes.dev/example_view:
How it works…
Pretty nice how simple this is! I have worked in other frameworks where making routes is a chore in abstraction and speed, or lack of speed.
In this case, we can quickly play with ideas and show results in a view right from the route. You could build an entire API in the route for small microservices.
In this case I just make an array, put it into the view using the php compact
syntax, and display it....