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'));
>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);