Support the ongoing development of Laravel.io →
posted 10 years ago
Blade
Last updated 2 years ago.
0

What do you need to inject? If you want to print variable do it this way:

{{ $variable }}
Last updated 2 years ago.
0

heihachi88 said:

What do you need to inject? If you want to print variable do it this way:

{{ $variable }}

Same question. But why you have to do so, using View::composer() & View::creator() may be a good idea.

Last updated 2 years ago.
0

I was really hoping to push a closure into the blade, but I suspect that the PHP in a blade is only parsed/executed once. I think that composer and creator may do what I want, so I'll have a look at them.

Thanks for your help!

Last updated 2 years ago.
0

Hi

I inject PHP into some of my blade views out of convenience because it is easier to write than go through the controller.

You can do something like this

<? require_once("app/config/db.php"); if (isset($suburb) && isset($postcode)){ $st = DBase::singleton() ->prepare( 'select `council`,`suburb` ' . 'from `suburb_near` ' . 'where `suburb` like :id and `postcode` like :pid'); $st->bindParam(':id', $suburb, PDO::PARAM_STR); $st->bindParam(':pid', $postcode, PDO::PARAM_STR); if ($st->execute()) { while ($row = $st->fetch(PDO::FETCH_OBJ)) { $council = $row->council; echo "{$suburb} is in the {$council}. "; echo "<br><a href='//seek.estate{$url}?council={$council}'>Click Here are all Properties in {$council}</a>"; } } } ?>

Which is what I'm using in my website https://seek.estate/buy to find all the properties in a given area.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.