Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Adds render function #100

Merged
merged 6 commits into from
Aug 30, 2023
Merged

[1.x] Adds render function #100

merged 6 commits into from
Aug 30, 2023

Conversation

nunomaduro
Copy link
Member

@nunomaduro nunomaduro commented Aug 29, 2023

Fixes #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>

@nunomaduro nunomaduro changed the title [1.x] Adds get function [1.x] Adds render function Aug 30, 2023
@nunomaduro nunomaduro marked this pull request as ready for review August 30, 2023 13:24
@inmanturbo
Copy link
Contributor

What a great idea! 👏

@taylorotwell taylorotwell merged commit a522a1a into master Aug 30, 2023
6 checks passed
@taylorotwell taylorotwell deleted the feat/get-function branch August 30, 2023 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Fragment directive
3 participants