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

[10.x] Allows HTTP exceptions to be thrown for views #47714

Merged
merged 1 commit into from
Jul 11, 2023

Conversation

nunomaduro
Copy link
Member

This pull request allows "http" exceptions to be thrown for views. Here is an example, when using blade's @php tags:

@php
    if (! Gate::check('view-books')) {
        abort(403);
    }

    $books = auth()->user()->books;
@endphp

@foreach ($books as $book)
    <div>
        {{ $book->title }}
    </div>
@endforeach

@nunomaduro nunomaduro requested a review from taylorotwell July 11, 2023 13:00
@nunomaduro nunomaduro marked this pull request as ready for review July 11, 2023 13:03
@taylorotwell taylorotwell merged commit 8098f6d into 10.x Jul 11, 2023
@taylorotwell taylorotwell deleted the feat/http-exceptions-on-views branch July 11, 2023 13:10
@ahinkle
Copy link
Contributor

ahinkle commented Jul 12, 2023

Are there any specific scenarios or use cases for this? I can't think of anything (including your example) where throwing HTTP Exceptions in Views is considered advantageous over the traditional approach.

Keeping the previous logic would encourage developers to use best practices such as the separation of concerns, promoting maintainability and reusability.

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.

3 participants