Created
May 14, 2016 15:48
-
-
Save leemason/1b22bfff25ba0d6a6da4a39281c67ad2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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