I have a store and a comments model set up, and I've created a relationship that should return all of the store comments concatenated together. This is working fine until I attempt to use eager loading, then the relationship will always return NULL.
This is the relationship:
public function FormattedStoreComments()
{
return $this->hasOne('App\Models\StoreComment','StoreID','StoreID')
->select(DB::raw("group_concat(DATE_FORMAT(StoreComment.created_at,'%Y-%m-%d'), ' - ', ShortName, ' - ', Comment, '\n' ORDER BY StoreComment.created_at DESC SEPARATOR '') as Comments"))
->join('users','StoreComment.created_by','=','users.UserID')
->groupBy('StoreID')
->whereNull('StoreComment.deleted_at')
->orderBy('StoreComment.created_at','DESC');
}
Is there any reason why this shouldn't be working with eager loading?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire