1. Go to this page and download the library: Download abbadon1334/laravel-apify library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
abbadon1334 / laravel-apify example snippets
use Apify\Laravel\Facades\Apify;
// Run an actor
$result = Apify::runActor('actor-id', [
'url' => 'https://example.com'
], [
'waitForFinish' => 60
]);
// Get dataset results
$data = Apify::getDataset('dataset-id');
// Get user information
$user = Apify::getUser();
use Apify\Laravel\ApifyClient;
class ScrapingService
{
public function __construct(private ApifyClient $apify)
{
}
public function scrapeWebsite(string $url): array
{
return $this->apify->runActor('web-scraper', [
'url' => $url
]);
}
}
// Run an actor and wait for completion
$result = Apify::runActor('actor-id', $input, [
'waitForFinish' => 60, // seconds
'memory' => 512, // MB
]);
// Run without waiting
$result = Apify::runActor('actor-id', $input, [
'waitForFinish' => 0
]);
// Get all items from a dataset
$items = Apify::getDataset('dataset-id');
// Get items with pagination
$items = Apify::getDataset('dataset-id', [
'limit' => 100,
'offset' => 200
]);
// Get specific fields only
$items = Apify::getDataset('dataset-id', [
'fields' => ['title', 'url', 'price']
]);
// Get a record from key-value store
$record = Apify::getKeyValueStore('store-id', 'record-key');
// Set a record in key-value store
Apify::setKeyValueStore('store-id', 'record-key', [
'data' => 'value'
]);
// Store binary data
Apify::setKeyValueStore('store-id', 'image.jpg', $binaryData, 'image/jpeg');
// Get actor run details
$run = Apify::getActorRun('run-id');
// Abort a running actor
$result = Apify::abortActorRun('run-id');
// List all available actors
$actors = Apify::listActors();
// List only your actors
$myActors = Apify::listActors(['my' => true]);
// Paginated listing
$actors = Apify::listActors([
'limit' => 50,
'offset' => 100
]);