9 months ago

Instantiate abstract class

Posted 9 months ago by ludo1960

Hi Guys,

After much reading and googling, hers's what's up: from

The crawler can be instantiated like this

    ->setCrawlObserver(<class that extends \Spatie\Crawler\CrawlObserver>)
The argument passed to setCrawlObserver must be an object that extends the \Spatie\Crawler\CrawlObserver abstract class:

So in my CrawlerCommand.php I added:


namespace App\Console\Commands;

use Illuminate\Console\Command;

use \Spatie\Crawler\CrawlObserver;

abstract class myClass extends CrawlObserver {


class CrawlerCommand extends Command

Then in my Handle Method I added:

    public function handle()
        //code goes here
        $myObject = new myClass(); //Change myClass to Object
        $url = ''; // Set to localhost site

So when I run php artisan crawler:crawl I get the following error:

   Symfony\Component\Debug\Exception\FatalThrowableError  : Cannot instantiate abstract class App\Console\Commands\myClass

  at /var/www/
    52|     public function handle()
    53|     {
    55|         //code goes here
  > 56|         $myObject = new myClass(); //Change myClass to Object
    57|         //$myObject = new CrawlObserver(); //instantiate
    58|         $url = ''; // Set to localhost site
    59|         Crawler::create()
    60|         ->setCrawlObserver($myObject)

  Exception trace:

  1   App\Console\Commands\CrawlerCommand::handle()

  2   call_user_func_array([])

Pretty sure i'm on the right track, but missing a fundamental step somewhere, any ideas guys?

Please sign in or create an account to participate in this conversation.