File manager - Edit - /home/asiatechinc/public_html/asiatech-websites/dynastyresort.com/app/Models/Meta.php
Back
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Request; class Meta extends Model { use HasFactory; // test /** * The table associated with the model. * * @var string */ protected $table = 'metas'; /** * The attributes that are mass assignable. * This makes it easy to save data using an array. * * @var array<int, string> */ protected $fillable = [ 'page_path', 'title', 'description', 'keywords', 'canonical_url', 'robots', 'og_title', 'og_description', 'og_image', 'og_site_name', 'og_type', 'og_locale', 'twitter_card', 'twitter_site', 'twitter_title', 'twitter_description', 'twitter_image', 'alternate_links', ]; /** * The attributes that should be cast. * 'alternate_links' is a JSON column, so we cast it to an array/object. * * @var array<string, string> */ protected $casts = [ 'alternate_links' => 'array', ]; // ========================================================= // UTILITY & SCOPE FUNCTIONS // ========================================================= /** * Scope a query to retrieve the meta data for the current request path. * * @param \Illuminate\Database\Eloquent\Builder $query * @return \Illuminate\Database\Eloquent\Builder */ public function scopeForCurrentPath($query) { // Get the current path (e.g., 'rooms/suite-a'). The root is '/' $path = Request::path() === '/' ? '/' : '/' . Request::path(); return $query->where('page_path', $path); } /** * Static helper method to fetch meta data for the current path. * This is the most common way you'll use this model. * * @return self|null */ public static function getCurrentPageMeta() { return self::forCurrentPath()->first(); } /** * Static helper method to fetch meta data for a specific path. * * @param string $path The page path/slug (e.g., '/contact-us') * @return self|null */ public static function getMetaByPath(string $path) { // Ensure path starts with a '/' unless it is just '/' $cleanPath = ($path !== '/' && !str_starts_with($path, '/')) ? '/' . $path : $path; return self::where('page_path', $cleanPath)->first(); } // ========================================================= // ACCESSOR FUNCTIONS (OPTIONAL) // ========================================================= /** * Accessor to get all standard SEO properties in a clean array. * Useful for passing to a Blade component. * * @return array */ public function getSeoAttributesAttribute(): array { return [ 'title' => $this->title, 'description' => $this->description, 'keywords' => $this->keywords, 'canonical_url' => $this->canonical_url, 'robots' => $this->robots, ]; } // You could similarly add an 'og_attributes' accessor here // ... }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings