1. Go to this page and download the library: Download gregoriohc/laravel-castable 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/ */
php
namespace App\Models;
use Gregoriohc\Castable\HasCustomCasts;
class Place extends \Illuminate\Database\Eloquent\Model
{
use HasCustomCasts;
protected $casts = [
'location' => 'point',
'bounding_box' => 'multipoint',
];
protected function castAttribute($key, $value)
{
return $this->customCastAttribute($key, parent::castAttribute($key, $value));
}
public function setAttribute($key, $value)
{
return parent::setAttribute($key, $value)->customSetAttribute($key, $value);
}
public function toArray()
{
return $this->customToArray(parent::toArray());
}
}
php
$place->location = [12.345, 67.890];
php
namespace \App\Casters;
class SerializableObject extends \Gregoriohc\Castable\Casters\Caster
{
public function as($value)
{
return unserialize($value);
}
public function from($value)
{
return serialize($value);
}
}