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

[0.x] Adds documentation about how to use PHP within Folio's blade views. #26

Merged
merged 2 commits into from
Jul 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- [Route Model Binding](#route-model-binding)
- [Soft Deleted Models](#soft-deleted-models)
- [Middleware](#middleware)
- [PHP Blocks](#php-blocks)
- [Contributing](#contributing)
- [Code of Conduct](#code-of-conduct)
- [Security Vulnerabilities](#security-vulnerabilities)
Expand Down Expand Up @@ -231,6 +232,29 @@ 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 Folio page definition functions such as `middleware` and `withTrashed`.

Therefore, if you need to write PHP code that should be executed within your Blade template, you should use the `@php` Blade directive:

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

$posts = $user->posts;
@endphp

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

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

Expand Down