Properties

ORM Model

Doorstep uses Laravel's brilliant ORM, Eloquent. Each database table, for instance properties, has a corresponding "Model" class which is used to interact with the data.

The vendor/doorstep/framework/src/Doorstep/Properties/Property.php file contains the Property Model class - feel free to browse this file to understand the methods and features.

Relationships

The Property model has a number of "relationships" to other models / tables in the database. These are:

  • agent
  • area
  • createdBy
  • councilTax
  • collections
  • media
  • propertyType

In Eloquent, these relationships allow you to query or access the related Models, whether the relationship is a one-to-one or a one-to-many.

For instance, assuming you have a $property variable available in your code / view, you can do the following:

echo $property->agent->nickname;

// Since $property->agent can be null if an agent isn't defined, 
// we can also wrap in a conditional.

if ( $property->agent ) {
    echo $property->agent->nickname;
}

// Or use shorthand

echo $property->agent ? $property->agent->nickname : '';

The media relation is a one-to-many relationship, so we can run queries on the underlying model. To return the relationship for querying, we access the method $property->media() rather than the attribute $property->media, like so:

$total = $property->media()->count();

$photos = $property->media()->orderBy('created_at', 'desc')->get();

Presenter