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

[5.6] Add @canany and @elsecanany blade directive #24137

Merged
merged 1 commit into from
May 17, 2018

Conversation

fuxu
Copy link
Contributor

@fuxu fuxu commented May 7, 2018

There is a use case for authorization directive

<table>
  <tr>
    <th>...</th>
    @canany(['edit_post', 'delete_post'])
    <th>Actions</th>
    @endcanany
  </tr>
  <tr>
    <td>...</td>
    @canany(['edit_post', 'delete_post'])
    <td>
      @can('edit_post')
      <button>Edit</button>
      @endcan
      @can('delete_post')
      <button>Delete</button>
      @endcan
    </td>
    @endcanany
  </tr>
</table>

I know I can implement it in AppServiceProvider::boot() using Custom If Statements as follow

Blade::if('canany', function ($abilities) {
    return app(\Illuminate\Contracts\Auth\Access\Gate::class)->any($abilities);
});

But I think it maybe helpful for others.

@tillkruss tillkruss changed the title Add @canany and @elsecanany blade directive [5.6] Add @canany and @elsecanany blade directive May 7, 2018
@taylorotwell taylorotwell merged commit 97edff8 into laravel:5.6 May 17, 2018
leoleoasd pushed a commit to leoleoasd/framework that referenced this pull request May 21, 2018
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.

2 participants