Preparing Your Model

To associate Open Graph Image with a model, the model must implement the following interface and trait:

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class YourModel extends Model implements HasGraphify
{
    use GraphifyTrait;
}

Graphify Image URL Field

The package assumes you have a nullable string field named og_image_url in your model. If you do not have such field, add the following line to your model migration. If your application is in production, you may need to add this to a modification migration.

 $table->string('og_image_url')->nullable();

If your model does have such a field but with a different field name, you may override the default by adding the following method to your model.

public function getOpenGraphImageUrlField(): string
{
    return 'your_custom_open_graph_image_url';
}

Last updated