Cast correctly binary data (mainly for PostgreSQL)
jbernavaprah/eloquent-binary-cast is a Laravel package for cast correctly binary data (mainly for postgresql).
It currently has 2 GitHub stars and 916 downloads on Packagist.
Install it with composer require jbernavaprah/eloquent-binary-cast.
Discover more Laravel packages by jbernavaprah
or browse all Laravel packages to compare alternatives.
Last updated
The Eloquent Binary Cast.
When using the PostgreSQL dialectic, Eloquent treat the "bytea" column in the same manner as blob/text column. But this is incorrect on PostgreSQL. The value needs to be cast before pushed to the database.
If you are not using Postgresql, you don't need this cast class.
See those issues:
composer require jbernavaprah/eloquent-binary-cast
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use JBernavaPrah\EloquentBinaryCast\BinaryCast;
class User extends Model
{
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'binary_data' => BinaryCast::class,
];
}
See https://laravel.com/docs/8.x/eloquent-mutators#custom-casts for more details.
composer test