PHP code example of robindrost / prismic-integration-field-laravel

1. Go to this page and download the library: Download robindrost/prismic-integration-field-laravel 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/ */

    

robindrost / prismic-integration-field-laravel example snippets


use RobinDrost\PrismicIntegrationField\IntegrationField;
use RobinDrost\PrismicIntegrationField\Contracts\IntegrationField as IntegrationFieldContract;

class MyModel extends Model implements ModelToIntegrationField
{
    // Using existing database fields
    public $fillable = [
        'id',
        'title',
        'description',
    ];

    // Using a getter method
    public function getImageUrlAttribute()
    {
        return 'https://via.placeholder.com/350x150';
    }

    // Convert this model to an integration field.
    public function toIntegrationField() : IntegrationFieldContract
    {
        IntegrationField::create()
            ->setId($this->id)
            ->setTitle($this->title)
            ->setDescription($this->description)
            ->setImageUrl($this->image_url)
            ->setUpdatedAt($this->updated_at->timestamp)
            ->setBlob([
                'id' => $this->id,
            ]);
    }
}

php artisan vendor:publish