Initial commit

This commit is contained in:
hackerESQ
2024-08-01 13:53:10 -05:00
commit 1984bff865
142 changed files with 17783 additions and 0 deletions
+106
View File
@@ -0,0 +1,106 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Portfolio extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'title',
'notes',
'wishlist',
];
/**
*
* @return void
*/
protected static function boot()
{
parent::boot();
static::saved(function ($model) {
self::syncUsers($model);
});
}
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [];
/**
* The relationships that should always be eagerly loaded.
*
* @var array
*/
protected $with = ['users'];
/**
* The attributes that should be appended.
*
* @var array
*/
protected $appends = ['owner_id'];
public function users()
{
return $this->belongsToMany(User::class)->withPivot('owner');
}
// public function holdings()
// {
// return $this->hasMany(Holding::class, 'portfolio_id', 'id');
// }
// public function transactions()
// {
// return $this->hasMany(Transaction::class);
// }
public function scopeMyPortfolios()
{
return $this->whereRelation('users', 'id', auth()->user()->id);
}
public function scopeWithoutWishlists()
{
return $this->where(['wishlist' => false]);
}
public function getOwnerIdAttribute()
{
return $this->users()->firstWhere('owner', 1)?->id;
}
public static function syncUsers(self $model) {
// make sure we don't remove owner access
$user_id[$model->owner_id ?? auth()->user()->id] = ['owner' => true];
// // add other users
// foreach(request()->users ?? [] as $id) {
// $user_id[$id] = ['owner' => false];
// };
// save
$model->users()->sync($user_id);
}
}
+75
View File
@@ -0,0 +1,75 @@
<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Fortify\TwoFactorAuthenticatable;
use Laravel\Jetstream\HasProfilePhoto;
use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable
{
use HasApiTokens;
use HasFactory;
use HasProfilePhoto;
use Notifiable;
use TwoFactorAuthenticatable;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
'two_factor_recovery_codes',
'two_factor_secret',
];
/**
* The accessors to append to the model's array form.
*
* @var array<int, string>
*/
protected $appends = [
'profile_photo_url',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
public function portfolios()
{
return $this->belongsToMany(Portfolio::class)->withPivot('owner');
}
// public function daily_changes()
// {
// return $this->hasMany(DailyChange::class);
// }
}