Файл: app/Models/Website.php
Строк: 85
<?php
namespace AppModels;
use IlluminateDatabaseEloquentBuilder;
use IlluminateDatabaseEloquentModel;
use IlluminateSupportFacadesCrypt;
/**
* Class Website
*
* @mixin Builder
* @package App
*/
class Website extends Model
{
/**
* @param Builder $query
* @param $value
* @return Builder
*/
public function scopeSearchDomain(Builder $query, $value)
{
return $query->where('domain', 'like', '%' . $value . '%');
}
/**
* Get the user that owns the website.
*/
public function user()
{
return $this->belongsTo('AppModelsUser')->withTrashed();
}
/**
* @param Builder $query
* @param $value
* @return Builder
*/
public function scopeOfUser(Builder $query, $value)
{
return $query->where('user_id', '=', $value);
}
/**
* Get the visitors count for a specific date range.
*
* @return Model|IlluminateDatabaseEloquentRelationsHasMany|object|null
*/
public function visitors()
{
return $this->hasMany('AppModelsStat', 'website_id', 'id')
->where('name', '=', 'visitors');
}
/**
* Get the pageviews count for a specific date range.
*
* @return Model|IlluminateDatabaseEloquentRelationsHasMany|object|null
*/
public function pageviews()
{
return $this->hasMany('AppModelsStat', 'website_id', 'id')
->where('name', '=', 'pageviews');
}
/**
* Get the website's stats.
*
* @return IlluminateDatabaseEloquentRelationsHasMany
*/
public function stats()
{
return $this->hasMany('AppModelsStat')->where('website_id', $this->id);
}
/**
* Get the website's recent stats.
*
* @return IlluminateDatabaseEloquentRelationsHasMany
*/
public function recents()
{
return $this->hasMany('AppModelsRecent')->where('website_id', $this->id);
}
/**
* Encrypt the website's password.
*
* @param $value
*/
public function setPasswordAttribute($value)
{
$this->attributes['password'] = Crypt::encryptString($value);
}
/**
* Decrypt the website's password.
*
* @param $value
* @return string
*/
public function getPasswordAttribute($value)
{
try {
return Crypt::decryptString($value);
} catch (Exception $e) {
return null;
}
}
}