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

sanjivsharma's avatar

Including php snippet in blade

Is it advisable to include php code in blade files , say xyz.blade.php. The reason I am asking is - I want to do some processing in the blade file before displaying the blade content. For example, I have a function in the controller -

public function index() {

    $tasks = Task::orderBy('created_at','dsc')->get();

    return view('index',compact('tasks'));

}

And following is the snippet from the blade file:

0 likes
3 replies
J_shelfwood's avatar

I don't think the snippet from the blade file came through properly?

phpMick's avatar

I don't think this would be a good idea but you need to post the code from the Blade file, so we can see what you are doing.

Mick

Please or to participate in this conversation.