for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Spatie\Activitylog\Traits\LogsActivity;
class Location extends Model
{
use LogsActivity;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'site_id'
];
* The attributes to ignore in the Activity Log
protected static $ignoreChangedAttributes = ['updated_at'];
* The attributes to log in the Activity Log
protected static $logAttributes = [
* Only log those that have actually changed after the update.
protected static $logOnlyDirty = true;
* Update the updated_at and created_at timestamps?
public $timestamps = true;
* Get the site for the location
public function site()
return $this->belongsTo('App\Site', 'site_id');
}
* Get devices for the location
public function devices()
return $this->hasMany('App\Device');
* Scope a query to only include locations belonging to a given site
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $site_id
* @return \Illuminate\Database\Eloquent\Builder
public function scopeBySite($query, $site_id)
return $query->where('site_id', $site_id);