Synchro back-office, fix on tariffs
This commit is contained in:
@@ -2,22 +2,68 @@
|
||||
|
||||
namespace App\Models\Core;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
use App\Repositories\Core\DateTime;
|
||||
use App\Traits\HasComments;
|
||||
|
||||
class Comment extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
use HasComments;
|
||||
|
||||
public function user()
|
||||
protected $fillable = [
|
||||
'comment',
|
||||
'user_id',
|
||||
'is_approved'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_approved' => 'boolean'
|
||||
];
|
||||
|
||||
public function scopeApproved($query)
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Core\Auth\User::class);
|
||||
return $query->where('is_approved', true);
|
||||
}
|
||||
|
||||
public function getUpdatedAtAttribute($value)
|
||||
public function commentable()
|
||||
{
|
||||
return DateTime::DateToLocale($value);
|
||||
}
|
||||
}
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
public function commentator()
|
||||
{
|
||||
return $this->belongsTo($this->getAuthModelName(), 'user_id');
|
||||
}
|
||||
|
||||
public function approve()
|
||||
{
|
||||
$this->update([
|
||||
'is_approved' => true,
|
||||
]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function disapprove()
|
||||
{
|
||||
$this->update([
|
||||
'is_approved' => false,
|
||||
]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getAuthModelName()
|
||||
{
|
||||
if (config('comments.user_model')) {
|
||||
return config('comments.user_model');
|
||||
}
|
||||
|
||||
if (!is_null(config('auth.providers.users.model'))) {
|
||||
return config('auth.providers.users.model');
|
||||
}
|
||||
|
||||
throw new Exception('Could not determine the commentator model name.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user