Skip to content

Instantly share code, notes, and snippets.

@leemason
Created May 14, 2016 15:48
Show Gist options
  • Save leemason/1b22bfff25ba0d6a6da4a39281c67ad2 to your computer and use it in GitHub Desktop.
Save leemason/1b22bfff25ba0d6a6da4a39281c67ad2 to your computer and use it in GitHub Desktop.
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Domain extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'host',
'user_id',
'screenshot',
'screenshot_updated'
];
public static function boot()
{
parent::boot();
//ensure we remove the scheme
static::creating(function($domain){
$domain->host = preg_replace("(^https?://)", "", $domain->host );
});
}
public function users(){
return $this->belongsToMany(User::class);
}
public function setPrimary(User $user){
$this->user_id = $user->id;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment