Initial Commit
This commit is contained in:
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user