Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

GTHell's avatar

Write PHP logic in Blade?

Currently, I only pass the data to blade through method Controller but I want to do live request and is it good practice to write a lot of PHP logic in Blade?

0 likes
5 replies
martinbean's avatar

is it good practice to write a lot of PHP logic in Blade?

@gthell No. It completely defeats the purpose of MVC.

Blade template are views. Your pass views the data they need via a controller. Your views should not be doing business logic.

Tray2's avatar

Blade is PHP and if you for some reason need to write custom php you can use the @php directive.

However lite the previous responses it is bad practice to use it to fetch data from the database. If you need to do that one the fly without reloading use JavaScript and fetch it from an API endpoint.

Please or to participate in this conversation.