Using PHP Traits for Laravel Eloquent Relationships
Sep 6, 2018 · 3 min read
I recently began refactoring a bunch of code on a project and found myself putting the same methods on my Eloquent models for a relation to an Account class. FYI I prefer to have getters and setters rather than accessing properties magically.
So lets say we have a Post model that looks something like this:
<?php
namespace App;use Illuminate\Database\Eloquent\Model;/**
* Class Post
*
* @package App
*/
class Post extends Model
{
/**
* @return string…

