Initial Commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class DirectMessage extends Model
|
||||
{
|
||||
protected $table = 'dm_messages';
|
||||
protected $primaryKey = 'id';
|
||||
public $incrementing = false;
|
||||
protected $keyType = 'string';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'id', 'thread_id', 'user_id', 'username', 'full_name', 'item_type', 'text',
|
||||
'media_url', 'is_video', 'timestamp', 'shared_url', 'shared_preview_image',
|
||||
'shared_title', 'shared_caption', 'reactions', 'replied_to_id', 'replied_to_text',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_video' => 'boolean',
|
||||
'timestamp' => 'integer',
|
||||
'reactions' => 'array',
|
||||
'scraped_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function thread(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DirectThread::class, 'thread_id', 'thread_id');
|
||||
}
|
||||
|
||||
public function repliedTo(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(self::class, 'replied_to_id', 'id');
|
||||
}
|
||||
|
||||
public function getSentAtAttribute(): ?\Carbon\Carbon
|
||||
{
|
||||
return $this->timestamp
|
||||
? \Carbon\Carbon::createFromTimestampMs($this->timestamp)
|
||||
: null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class DirectThread extends Model
|
||||
{
|
||||
protected $table = 'dm_threads';
|
||||
protected $primaryKey = 'thread_id';
|
||||
public $incrementing = false;
|
||||
protected $keyType = 'string';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'thread_id', 'thread_key', 'thread_title', 'is_group',
|
||||
'participants', 'last_activity_at', 'muted',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'participants' => 'array',
|
||||
'is_group' => 'boolean',
|
||||
'muted' => 'boolean',
|
||||
'last_activity_at' => 'integer',
|
||||
'scraped_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function messages(): HasMany
|
||||
{
|
||||
return $this->hasMany(DirectMessage::class, 'thread_id', 'thread_id');
|
||||
}
|
||||
|
||||
public function getLastActivityAtDateAttribute(): ?\Carbon\Carbon
|
||||
{
|
||||
return $this->last_activity_at
|
||||
? \Carbon\Carbon::createFromTimestampMs($this->last_activity_at)
|
||||
: null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Post extends Model
|
||||
{
|
||||
protected $table = 'posts';
|
||||
|
||||
// Instagram's own post pk is the primary key, not auto-increment
|
||||
protected $keyType = 'string';
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
// scraped_at is set by the DB default; created_at/updated_at don't apply
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'code',
|
||||
'username',
|
||||
'full_name',
|
||||
'caption',
|
||||
'accessibility_caption',
|
||||
'is_video',
|
||||
'is_carousel',
|
||||
'like_count',
|
||||
'comment_count',
|
||||
'taken_at',
|
||||
'image_url',
|
||||
'video_url',
|
||||
'carousel_images',
|
||||
'scraped_at',
|
||||
'profile_pic_url',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_video' => 'boolean',
|
||||
'is_carousel' => 'boolean',
|
||||
'like_count' => 'integer',
|
||||
'comment_count' => 'integer',
|
||||
'taken_at' => 'integer',
|
||||
'carousel_images' => 'array',
|
||||
'scraped_at' => 'datetime',
|
||||
'taken_at_date' => 'datetime',
|
||||
'permalink' => 'string',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'permalink',
|
||||
'taken_at_date',
|
||||
];
|
||||
|
||||
/**
|
||||
* Instagram's taken_at is a unix timestamp - convenience accessor
|
||||
* for an actual Carbon instance.
|
||||
*/
|
||||
protected function takenAtDate(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn () => $this->taken_at ? Carbon::createFromTimestamp($this->taken_at) : null,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience: the actual instagram.com URL for this post.
|
||||
*/
|
||||
protected function permalink(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn () => $this->code ? "https://www.instagram.com/p/{$this->code}/" : null,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Story extends Model
|
||||
{
|
||||
protected $table = 'stories';
|
||||
|
||||
protected $keyType = 'string';
|
||||
public $incrementing = false;
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'id', 'user_id', 'username', 'profile_pic_url', 'code',
|
||||
'is_video', 'taken_at', 'expiring_at', 'image_url', 'video_url',
|
||||
'accessibility_caption', 'muted', 'scraped_at',
|
||||
'viewed_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_video' => 'boolean',
|
||||
'taken_at' => 'integer',
|
||||
'expiring_at' => 'integer',
|
||||
|
||||
'muted' => 'boolean',
|
||||
'scraped_at' => 'datetime',
|
||||
'viewed_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('expiring_at', '>', now()->timestamp);
|
||||
}
|
||||
|
||||
public function getIsUnreadAttribute(): bool
|
||||
{
|
||||
return $this->viewed_at === null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Laravel\Fortify\Contracts\PasskeyUser;
|
||||
use Laravel\Fortify\PasskeyAuthenticatable;
|
||||
use Laravel\Fortify\TwoFactorAuthenticatable;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $email
|
||||
* @property Carbon|null $email_verified_at
|
||||
* @property string $password
|
||||
* @property string|null $two_factor_secret
|
||||
* @property string|null $two_factor_recovery_codes
|
||||
* @property Carbon|null $two_factor_confirmed_at
|
||||
* @property string|null $remember_token
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
*/
|
||||
#[Fillable(['name', 'email', 'password'])]
|
||||
#[Hidden(['password', 'two_factor_secret', 'two_factor_recovery_codes', 'remember_token'])]
|
||||
class User extends Authenticatable implements PasskeyUser
|
||||
{
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, Notifiable, PasskeyAuthenticatable, TwoFactorAuthenticatable;
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'two_factor_confirmed_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user