laravel / folio

Page based routing for Laravel.
MIT License
568 stars 46 forks source link

[1.x] Adds `render` function #100

Closed nunomaduro closed 1 year ago

nunomaduro commented 1 year ago

Fixes https://github.com/laravel/folio/issues/99.

This pull request adds the render functio, and it allows to hook into the request to add custom data, specify fragments, etc. This is very powerful because we can even return a different response.

Here is an example, where we are performing validation using the get function, and adding additional data to the view:

<?php

use function Laravel\Folio\render;

render(function (View $view, User $user) {
    if (! Gate::check('view', $user)) {
        return to_route('users.index');
    }

    return $view->with('posts', $user->posts);
})->name('users.show') ?>

<div>
    <!-- Template here. This available variables are: $user and $posts now... -->
</div>
inmanturbo commented 1 year ago

What a great idea! :clap: