@lucasvrm Try this:
$browsershot = new \Spatie\Browsershot\Browsershot();
Or, import it at the top and then use it:
use Spatie\Browsershot\Browsershot;
...
public function create_preview()
{
$browsershot = new Browsershot();
...
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello there!
I´ve installed a package called spatie/browsershot and I followed the steps showed here https://github.com/spatie/browsershot
But it's not working at all...
I am new to laravel, so probably this is a silly mistake... What I am doing wrong?
function inside a controller
public function create_preview()
{
$findhash = Link::where('hash', '=', $hash)->firstOrFail();
$browsershot = new Spatie\Browsershot\Browsershot();
$browsershot
->setURL($findhash->url)
->setWidth('1024')
->setHeight('768')
->save('previews/'.$findhash->url.'.jpg');
return view('pages.teste2');
}
composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"guzzlehttp/guzzle": "~6.0",
"greggilbert/recaptcha": "^2.0",
"symfony/dom-crawler": "^2.7",
"fabpot/goutte": "^3.1",
"pragmarx/tracker": "^1.0",
"geoip/geoip": "~1.14",
"spatie/laravel-analytics": "^1.2",
"roumen/sitemap": "^2.5",
"ramsey/uuid": "^2.8",
"intervention/image": "^2.3",
"spatie/browsershot": "^1.2"
..........
Please or to participate in this conversation.