Skip to content

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

Merged
taylorotwell merged 1 commit into
laravel:5.6from
fuxu:add-canany-directive
May 17, 2018
Merged

[5.6] Add @canany and @elsecanany blade directive#24137
taylorotwell merged 1 commit into
laravel:5.6from
fuxu:add-canany-directive

Conversation

@fuxu
Copy link
Copy Markdown
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