Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

LARAVEL | How to use compacted variable in Blade Syntax (@php … @endphp)

I am building a Scraping tool that lets the user provide a website. I want to insert the provided website from the DB into the PHP function file_get_html(). since it’s a PHP function I have to put it between @php && @endphp tags but this code doesn’t work:

@php
include('../public/simple_html_dom.php');

$html = file_get_html({{$scrape_res->website}});
.
.
.
@endphp

The $scrape_res variable is passed through a Controller like this:

$scrape_res = Scrapes::latest('id')->first();

return view('scrape', compact('scrape_res'));

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I’d advise you to look into MVC a bit more. You shouldn’t handle this kind of login in your template, it should go in the controller. That being said:

In your blade code you have

$html = file_get_html({{$scrape_res->website}});

within a PHP block. The {{ .. }} is only to echo vars in blade, but it’s not necessary here. So, change the line to

$html = file_get_html($scrape_res->website);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading