Skip to content

Commit

Permalink
Adds documentation about blade views
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Jul 11, 2023
1 parent cc45beb commit a6adb7d
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,37 @@ Folio::route(resource_path('views/pages'), middleware: [
]);
```

<a name="php-blocks"></a>
## PHP Blocks

When using Folio, the `<?php` and `?>` tags are reserved for the page definition via Folio specific functions such as `middleware` or `withTrashed`.

Therefore, in occasions where you need to write PHP code to be executed within your blade view, you should use the `@php` blade directive:

As an example, if you need to check if a user can view other user's posts, you can do so by using the `@php` directive:

```bash
php artisan folio:make posts

# pages/users/[User].blade.php → /users/1
```

```php
@php
if (! auth()->user()->can('posts-view', $user)) {
abort(403);
}

$posts = $user->posts;
@endphp

@foreach ($posts as $post)
<div>
{{ $post->title }}
</div>
@endforeach
```

## Contributing
<a name="contributing"></a>

Expand Down

0 comments on commit a6adb7d

Please sign in to comment.