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

@elsecan / @elsecannot functionality #13048

Closed
ngaugler opened this issue Apr 6, 2016 · 4 comments
Closed

@elsecan / @elsecannot functionality #13048

ngaugler opened this issue Apr 6, 2016 · 4 comments

Comments

@ngaugler
Copy link

ngaugler commented Apr 6, 2016

Is there a way to effectuate @else and @can into blades? I have run into a situation where I need to leverage @elsecan() but do not see this functionality in Laravel. Below is a basic example:

@can('read-write')
<li>Read/Write</li>
@elsecan('write')
<li>Write</li>
@elsecan('read')
<li>Read</li>
@else
<li>None</li>
@end

If a new feature is added for @elsecan, it would make sense to add @elsecannot at the same.

---Edit---
I ended up creating my own directive in AppServiceProvider::boot(), but this is probably a useful directive for others.

Blade::directive('elsecan', function($expression) {
    return "<?php elseif (Gate::check{$expression}): ?>";
});
@themsaid
Copy link
Member

@GrahamCampbell this too can be closed

@GrahamCampbell
Copy link
Member

Thank you.

@GrahamCampbell
Copy link
Member

GrahamCampbell commented Apr 29, 2016

In future, please format PR bodies so they actually contain the text Closes #13048 ;)

@themsaid
Copy link
Member

I started doing that already in my latest PRs, making your job a bit easier ;)

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

No branches or pull requests

3 participants