$post = Post::find(1);
// For example, imagine we have an \App\Services\CustomLocation class,
// that implements any custom logics and for some reasons
// we have to store it in DB as it is.
// Let's instantinate it.
$location = new \App\Services\CustomLocation(55.9937441, 92.7521816);
// And call some methods, imagine we have them there.
$location->updatePosition();
$location->callAPI();
// After that, we want to save it in our post model.
// We can just assign the value and call default save() method.
$post->geo_location = $location;
$post->save();
// It's saved. Let's get a post again
// and check the field class.
$post = Post::find(1);
var_dump($post instanceof \App\Services\CustomLocation);
// Outputs:
// bool(true)
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.