PHP code example of daltonmccleery / remote-models
1. Go to this page and download the library: Download daltonmccleery/remote-models 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/ */
daltonmccleery / remote-models example snippets
class Celebrity extends Model
{
use \RemoteModels\RemoteModel;
}
class Celebrity extends Model implements \RemoteModels\Interfaces\RemoteModelInterface
{
use \RemoteModels\RemoteModelManagement;
public function migrate(): void
{
$this->createRemoteModelTable(schemaCallback: function (array $schema) {
// Make any modifications to the column schema before the sqlite table is created.
return $schema;
});
$this->loadRemoteModelData();
}
public function loadRemoteModelData(int $page = 1): void
{
// Normal operation is a POST request with the config API key,
// but you are free to modify the API call as you like.
$response = \Illuminate\Support\Facades\Http::get($this->getRemoteModelEndpoint());
$data = $response->json();
// `insertRemoteModelData` is available and takes an array of data to be inserted.
$this->insertRemoteModelData($data['data'], $data['per_page'] ?? 15);
// Call the next page, if available.
if ((int) $data['current_page'] < (int) $data['last_page']) {
$this->loadRemoteModelData((int) $data['current_page'] + 1);
}
}
}