use native lara notifs, add phpsandbox package
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Models\Concerns;
|
||||
|
||||
|
||||
use App\Models\ContentReport;
|
||||
use App\Models\Notification;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
trait NotificationContext
|
||||
{
|
||||
public function bootNotificationContext()
|
||||
{
|
||||
static::deleting(function(NotificationContext $self) {
|
||||
$self->notificationsAbout()->delete();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifications having this model as a context
|
||||
*
|
||||
* @return MorphMany
|
||||
*/
|
||||
public function notificationsAbout()
|
||||
{
|
||||
return $this->morphMany(Notification::class, 'context');
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,9 @@ namespace App\Models\Concerns;
|
||||
use App\Models\ContentReport;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
/**
|
||||
* @property ContentReport $reportsOf
|
||||
*/
|
||||
trait Reportable
|
||||
{
|
||||
public function bootReportable()
|
||||
|
||||
@@ -16,7 +16,6 @@ use Illuminate\Database\Eloquent\Model;
|
||||
class Proposal extends Model
|
||||
{
|
||||
use Reportable;
|
||||
use NotificationContext;
|
||||
|
||||
/** Authoring user */
|
||||
public function author()
|
||||
|
||||
@@ -12,7 +12,6 @@ use Illuminate\Database\Eloquent\Model;
|
||||
class Table extends Model
|
||||
{
|
||||
use Reportable;
|
||||
use NotificationContext;
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
|
||||
@@ -12,7 +12,6 @@ use Illuminate\Database\Eloquent\Model;
|
||||
class TableComment extends Model
|
||||
{
|
||||
use Reportable;
|
||||
use NotificationContext;
|
||||
|
||||
/** Context data table */
|
||||
public function table()
|
||||
|
||||
+16
-21
@@ -4,16 +4,29 @@ namespace App\Models;
|
||||
|
||||
use AdamWathan\EloquentOAuth\OAuthIdentity;
|
||||
use App\Models\Concerns\Reportable;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
|
||||
/**
|
||||
* A user in the application
|
||||
*
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $updated_at
|
||||
* @property string $name - unique, for vanity URL
|
||||
* @property string $email - unique, for login and social auth chaining
|
||||
* @property string $password - hashed pw
|
||||
* @property Proposal[]|Collection $proposals
|
||||
* @property Table[]|Collection $tables
|
||||
* @property OAuthIdentity[]|Collection $socialIdentities
|
||||
* @property TableComment[]|Collection $tableComments
|
||||
* @property Table[]|Collection $favouriteTables
|
||||
* @property Table[]|Collection $followedDiscussions
|
||||
* @property ContentReport[]|Collection $authoredReports
|
||||
* @property Notification[]|Collection $notifications
|
||||
* @property Notification[]|Collection $readNotifications
|
||||
* @property Notification[]|Collection $unreadNotifications
|
||||
*/
|
||||
class User extends Authenticatable
|
||||
{
|
||||
@@ -47,13 +60,11 @@ class User extends Authenticatable
|
||||
foreach ($self->proposals as $proposal) {
|
||||
$proposal->delete();
|
||||
}
|
||||
|
||||
$self->notificationsCaused()->delete();
|
||||
});
|
||||
}
|
||||
|
||||
/** Owned tables */
|
||||
public function dataTables()
|
||||
public function tables()
|
||||
{
|
||||
return $this->hasMany(Table::class, 'owner_id');
|
||||
}
|
||||
@@ -94,22 +105,6 @@ class User extends Authenticatable
|
||||
return $this->hasMany(ContentReport::class, 'author_id');
|
||||
}
|
||||
|
||||
/** Notifications for this user */
|
||||
public function notifications()
|
||||
{
|
||||
return $this->hasMany(Notification::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifications caused by this user
|
||||
*
|
||||
* @return HasMany
|
||||
*/
|
||||
public function notificationsCaused()
|
||||
{
|
||||
return $this->hasMany(Notification::class, 'actor_id');
|
||||
}
|
||||
|
||||
// --------- Relation Helpers ---------
|
||||
|
||||
public function addFavourite(Table $table)
|
||||
|
||||
Reference in New Issue
Block a user