parent
ce88fd3978
commit
34df868d57
@ -0,0 +1,23 @@ |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
/** |
||||
* Report (something objectionable spotted by a user) |
||||
*/ |
||||
class ContentReport extends Model |
||||
{ |
||||
/** Authoring user */ |
||||
public function author() |
||||
{ |
||||
return $this->belongsTo(User::class, 'author_id'); |
||||
} |
||||
|
||||
/** Authoring user */ |
||||
public function object() |
||||
{ |
||||
return $this->morphTo(); |
||||
} |
||||
} |
@ -0,0 +1,51 @@ |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
/** |
||||
* Notification received by a user |
||||
*/ |
||||
class Notification extends Model |
||||
{ |
||||
/** Recipient user */ |
||||
public function user() |
||||
{ |
||||
return $this->belongsTo(User::class, 'user_id'); |
||||
} |
||||
|
||||
/** User who triggered this notification */ |
||||
public function actor() |
||||
{ |
||||
return $this->belongsTo(User::class, 'actor_id'); |
||||
} |
||||
|
||||
/** Notification context (what was affected) */ |
||||
public function context() |
||||
{ |
||||
return $this->morphTo(); |
||||
} |
||||
|
||||
/** |
||||
* Unseen notifications |
||||
* |
||||
* @param \Illuminate\Database\Eloquent\Builder $query |
||||
* @return \Illuminate\Database\Eloquent\Builder |
||||
*/ |
||||
public function scopeUnseen($query) |
||||
{ |
||||
return $query->where('seen', false); |
||||
} |
||||
|
||||
/** |
||||
* Seen notifications |
||||
* |
||||
* @param \Illuminate\Database\Eloquent\Builder $query |
||||
* @return \Illuminate\Database\Eloquent\Builder |
||||
*/ |
||||
public function scopeSeen($query) |
||||
{ |
||||
return $query->where('seen', true); |
||||
} |
||||
} |
@ -0,0 +1,41 @@ |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
/** |
||||
* Comment on a data table |
||||
*/ |
||||
class TableComment extends Model |
||||
{ |
||||
/** Context data table */ |
||||
public function dataTable() |
||||
{ |
||||
return $this->belongsTo(DataTable::class); |
||||
} |
||||
|
||||
/** Parent comment (that we reply to; can be null) */ |
||||
public function ancestor() |
||||
{ |
||||
return $this->belongsTo(TableComment::class, 'ancestor_id'); |
||||
} |
||||
|
||||
/** Replies to this comment */ |
||||
public function replies() |
||||
{ |
||||
return $this->hasMany(TableComment::class, 'ancestor_id'); |
||||
} |
||||
|
||||
/** Authoring user */ |
||||
public function author() |
||||
{ |
||||
return $this->belongsTo(User::class, 'author_id'); |
||||
} |
||||
|
||||
/** Reports of this comment */ |
||||
public function reportsOf() |
||||
{ |
||||
return $this->morphMany(ContentReport::class, 'object'); |
||||
} |
||||
} |
Loading…
Reference in new issue