Add (initial): futurewalker code
This commit is contained in:
39
app/Models/Entity.php
Normal file
39
app/Models/Entity.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class Entity
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
*
|
||||
* @property Collection|PostEntity[] $post_entities
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class Entity extends Model
|
||||
{
|
||||
protected $table = 'entities';
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'slug',
|
||||
'description'
|
||||
];
|
||||
|
||||
public function post_entities()
|
||||
{
|
||||
return $this->hasMany(PostEntity::class);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@@ -17,74 +18,93 @@
|
||||
* Class Post
|
||||
*
|
||||
* @property int $id
|
||||
* @property int|null $serp_url_id
|
||||
* @property string|null $title
|
||||
* @property string|null $slug
|
||||
* @property string|null $type
|
||||
* @property string|null $excerpt
|
||||
* @property string|null $main_keyword
|
||||
* @property string|null $keywords
|
||||
* @property string|null $bites
|
||||
* @property int|null $author_id
|
||||
* @property bool $featured
|
||||
* @property string|null $featured_image
|
||||
* @property string|null $body
|
||||
* @property int $views_count
|
||||
* @property string $status
|
||||
* @property Carbon|null $published_at
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property SerpUrl|null $serp_url
|
||||
* @property Author|null $author
|
||||
* @property Collection|PostCategory[] $post_categories
|
||||
* @property Carbon $published_at
|
||||
*/
|
||||
class Post extends Model implements Feedable
|
||||
{
|
||||
protected $table = 'posts';
|
||||
|
||||
protected $casts = [
|
||||
'serp_url_id' => 'int',
|
||||
'author_id' => 'int',
|
||||
'featured' => 'bool',
|
||||
'views_count' => 'int',
|
||||
'keywords' => 'array',
|
||||
'published_at' => 'datetime',
|
||||
'keywords' => 'array',
|
||||
'metadata' => 'object',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'serp_url_id',
|
||||
'title',
|
||||
'short_title',
|
||||
'slug',
|
||||
'type',
|
||||
'excerpt',
|
||||
'main_keyword',
|
||||
'keywords',
|
||||
'bites',
|
||||
'author_id',
|
||||
'featured',
|
||||
'featured_image',
|
||||
'body',
|
||||
'views_count',
|
||||
'status',
|
||||
'main_keyword',
|
||||
'keywords',
|
||||
'published_at',
|
||||
'metadata',
|
||||
'society_impact',
|
||||
'society_impact_level',
|
||||
];
|
||||
|
||||
public function getFeaturedImageLqipCdnAttribute()
|
||||
protected function featuredImage(): Attribute
|
||||
{
|
||||
if (! is_empty($this->featured_image)) {
|
||||
// Get the extension of the original featured image
|
||||
$extension = pathinfo($this->featured_image, PATHINFO_EXTENSION);
|
||||
return Attribute::make(
|
||||
get: function ($value = null) {
|
||||
if (! is_empty($value)) {
|
||||
return Storage::disk('r2')->url($value);
|
||||
}
|
||||
|
||||
// Append "_lqip" before the extension to create the LQIP image URL
|
||||
$lqipFeaturedImage = str_replace(".{$extension}", '_lqip.webp', $this->featured_image);
|
||||
return null;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return 'https://'.Storage::disk('r2')->url($lqipFeaturedImage).'?a=bc';
|
||||
protected function getFeaturedThumbImageAttribute()
|
||||
{
|
||||
$value = $this->featured_image;
|
||||
|
||||
//dd($value);
|
||||
|
||||
if (! is_empty($value)) {
|
||||
// Extract the file extension
|
||||
$extension = pathinfo($value, PATHINFO_EXTENSION);
|
||||
|
||||
// Construct the thumbnail filename by appending '_thumb' before the extension
|
||||
$thumbnail = str_replace(".{$extension}", "_thumb.{$extension}", $value);
|
||||
|
||||
return $thumbnail;
|
||||
|
||||
// Return the full URL to the thumbnail image
|
||||
//return Storage::disk('r2')->url($thumbnail);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getFeaturedImageCdnAttribute()
|
||||
public function serp_url()
|
||||
{
|
||||
if (! is_empty($this->featured_image)) {
|
||||
return 'https://'.Storage::disk('r2')->url($this->featured_image);
|
||||
}
|
||||
|
||||
return null;
|
||||
return $this->belongsTo(SerpUrl::class);
|
||||
}
|
||||
|
||||
public function author()
|
||||
@@ -92,6 +112,16 @@ public function author()
|
||||
return $this->belongsTo(Author::class);
|
||||
}
|
||||
|
||||
public function post_categories()
|
||||
{
|
||||
return $this->hasMany(PostCategory::class);
|
||||
}
|
||||
|
||||
public function post_entities()
|
||||
{
|
||||
return $this->hasMany(PostEntity::class);
|
||||
}
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->hasOneThrough(
|
||||
@@ -104,15 +134,27 @@ public function category()
|
||||
);
|
||||
}
|
||||
|
||||
public function entities()
|
||||
{
|
||||
return $this->hasManyThrough(
|
||||
Entity::class, // The target model
|
||||
PostEntity::class, // The through model
|
||||
'post_id', // The foreign key on the through model
|
||||
'id', // The local key on the parent model (Post)
|
||||
'id', // The local key on the through model (PostEntity)
|
||||
'entity_id' // The foreign key on the target model (Entity)
|
||||
);
|
||||
}
|
||||
|
||||
public function toFeedItem(): FeedItem
|
||||
{
|
||||
return FeedItem::create([
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'summary' => $this->excerpt,
|
||||
'summary' => $this->bites,
|
||||
'updated' => $this->updated_at,
|
||||
'link' => route('front.post', ['slug' => $this->slug, 'category_slug' => $this->category->slug]),
|
||||
'authorName' => optional($this->author)->name,
|
||||
'authorName' => 'FutureWalker',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
49
app/Models/PostEntity.php
Normal file
49
app/Models/PostEntity.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class PostEntity
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $post_id
|
||||
* @property int $entity_id
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
*
|
||||
* @property Post $post
|
||||
* @property Entity $entity
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class PostEntity extends Model
|
||||
{
|
||||
protected $table = 'post_entities';
|
||||
|
||||
protected $casts = [
|
||||
'post_id' => 'int',
|
||||
'entity_id' => 'int'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'post_id',
|
||||
'entity_id'
|
||||
];
|
||||
|
||||
public function post()
|
||||
{
|
||||
return $this->belongsTo(Post::class);
|
||||
}
|
||||
|
||||
public function entity()
|
||||
{
|
||||
return $this->belongsTo(Entity::class);
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,12 @@ class SerpUrl extends Model
|
||||
'category_id' => 'int',
|
||||
'process_status' => 'int',
|
||||
'serp_at' => 'datetime',
|
||||
'picked' => 'boolean',
|
||||
'processed' => 'boolean',
|
||||
'crawled' => 'boolean',
|
||||
'written' => 'boolean',
|
||||
'url_posted_at' => 'datetime',
|
||||
'suggestion_data' => 'object',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
@@ -51,6 +57,12 @@ class SerpUrl extends Model
|
||||
'process_status',
|
||||
'serp_at',
|
||||
'status',
|
||||
'picked',
|
||||
'processed',
|
||||
'crawled',
|
||||
'written',
|
||||
'url_posted_at',
|
||||
'suggestion_data',
|
||||
];
|
||||
|
||||
public function news_serp_result()
|
||||
|
||||
44
app/Models/SerpUrlResearch.php
Normal file
44
app/Models/SerpUrlResearch.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class SerpUrlResearch
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $serp_url_id
|
||||
* @property string $url
|
||||
* @property string $query
|
||||
* @property string|null $content
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property SerpUrl $serp_url
|
||||
*/
|
||||
class SerpUrlResearch extends Model
|
||||
{
|
||||
protected $table = 'serp_url_researches';
|
||||
|
||||
protected $casts = [
|
||||
'serp_url_id' => 'int',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'serp_url_id',
|
||||
'url',
|
||||
'query',
|
||||
'content',
|
||||
'main_image',
|
||||
];
|
||||
|
||||
public function serp_url()
|
||||
{
|
||||
return $this->belongsTo(SerpUrl::class);
|
||||
}
|
||||
}
|
||||
44
app/Models/ServiceCostUsage.php
Normal file
44
app/Models/ServiceCostUsage.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class ServiceCostUsage
|
||||
*
|
||||
* @property int $id
|
||||
* @property float $cost
|
||||
* @property string $name
|
||||
* @property string|null $reference_1
|
||||
* @property string|null $reference_2
|
||||
* @property string $output
|
||||
* @property string|null $input_1
|
||||
* @property string|null $input_2
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
*/
|
||||
class ServiceCostUsage extends Model
|
||||
{
|
||||
protected $table = 'service_cost_usages';
|
||||
|
||||
protected $casts = [
|
||||
'cost' => 'float',
|
||||
'output' => 'object',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'cost',
|
||||
'name',
|
||||
'reference_1',
|
||||
'reference_2',
|
||||
'output',
|
||||
'input_1',
|
||||
'input_2',
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user