Skip to content

Commit

Permalink
Fixed localize url for seo
Browse files Browse the repository at this point in the history
  • Loading branch information
sagsoz06 committed Feb 19, 2019
1 parent c940aba commit 87b3026
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 30 deletions.
5 changes: 5 additions & 0 deletions Entities/Brand.php
Expand Up @@ -21,4 +21,9 @@ public function portfolios()
{
return $this->hasMany(Portfolio::class);
}

public function getUrlAttribute()
{
return localize_trans_url(locale(), 'portfolio::routes.brand.slug', ['slug'=>$this->slug]);
}
}
7 changes: 7 additions & 0 deletions Entities/BrandTranslation.php
Expand Up @@ -9,4 +9,11 @@ class BrandTranslation extends Model
public $timestamps = false;
protected $fillable = ['title', 'slug'];
protected $table = 'portfolio__brand_translations';

protected $appends = ['url'];

public function getUrlAttribute()
{
return localize_trans_url($this->locale, 'portfolio::routes.brand.slug', ['slug'=>$this->slug]);
}
}
5 changes: 1 addition & 4 deletions Entities/Category.php
Expand Up @@ -22,11 +22,8 @@ public function portfolios()
return $this->belongsToMany(Portfolio::class, 'portfolio__portfolio_categories');
}

/**
* @return string
*/
public function getUrlAttribute()
{
return route('portfolio.category.slug', [$this->slug]);
return localize_trans_url(locale(), 'portfolio::routes.category.slug', ['slug'=>$this->slug]);
}
}
7 changes: 7 additions & 0 deletions Entities/CategoryTranslation.php
Expand Up @@ -9,4 +9,11 @@ class CategoryTranslation extends Model
public $timestamps = false;
protected $fillable = ['title', 'slug'];
protected $table = 'portfolio__category_translations';

protected $appends = ['url'];

public function getUrlAttribute()
{
return localize_trans_url($this->locale, 'portfolio::routes.category.slug', ['slug'=>$this->slug]);
}
}
32 changes: 12 additions & 20 deletions Entities/Portfolio.php
Expand Up @@ -5,6 +5,7 @@
use Dimsav\Translatable\Translatable;
use Illuminate\Database\Eloquent\Model;
use Laracasts\Presenter\PresentableTrait;
use Modules\Core\Models\Scopes\ActiveScope;
use Modules\Core\Traits\NamespacedEntity;
use Modules\Media\Support\Traits\MediaRelation;
use Carbon\Carbon;
Expand All @@ -21,6 +22,9 @@ class Portfolio extends Model implements TaggableInterface
protected $fillable = ['category_id', 'brand_id', 'title', 'slug', 'description', 'meta_title', 'meta_description', 'website', 'ordering', 'status', 'start_at', 'end_at', 'settings'];
protected $dates = ['start_at', 'end_at'];
protected $with = ['brand', 'category'];
protected $casts = [
'settings' => 'object'
];

protected static $entityNamespace = 'asgardcms/portfolio';

Expand Down Expand Up @@ -51,35 +55,16 @@ public function brand()
return $this->belongsTo(Brand::class, 'brand_id');
}

/**
* @return string
*/
public function getUrlAttribute()
{
return route('portfolio.slug', [$this->slug]);
}

public function setSettingsAttribute($value)
{
return $this->attributes['settings'] = json_encode($value);
}

public function getSettingsAttribute()
{
$settings = json_decode($this->attributes['settings']);
return $settings;
return localize_trans_url(locale(), 'portfolio::routes.portfolio.slug', ['slug'=>$this->slug]);
}

public function hasImage()
{
return $this->files()->exists();
}

public function scopeActivated($query)
{
return $query->whereStatus(1);
}

public function scopeWithTransRelated($query)
{
return $query->with(['translations','category','brand']);
Expand All @@ -89,4 +74,11 @@ public function scopeWithRelated($query)
{
return $query->with(['category','brand']);
}

protected static function boot()
{
parent::boot();

static::addGlobalScope(new ActiveScope());
}
}
9 changes: 8 additions & 1 deletion Entities/PortfolioCategory.php
Expand Up @@ -7,4 +7,11 @@ class PortfolioCategory extends Model
public $timestamps = false;
protected $table = 'portfolio__portfolio_categories';
protected $fillable = ['portfolio_id', 'category_id'];
}

protected $appends = ['url'];

public function getUrlAttribute()
{
return localize_trans_url($this->locale, 'portfolio::routes.category.slug', ['slug'=>$this->slug]);
}
}
7 changes: 7 additions & 0 deletions Entities/PortfolioTranslation.php
Expand Up @@ -10,8 +10,15 @@ class PortfolioTranslation extends Model
protected $fillable = ['title', 'slug', 'description', 'meta_title', 'meta_description'];
protected $table = 'portfolio__portfolio_translations';

protected $appends = ['url'];

public function getTitleAttribute()
{
return $this->attributes['meta_title'] ? $this->attributes['meta_title'] : $this->attributes['title'];
}

public function getUrlAttribute()
{
return localize_trans_url($this->locale, 'portfolio::routes.portfolio.slug', ['slug'=>$this->slug]);
}
}
8 changes: 3 additions & 5 deletions module.json
Expand Up @@ -9,9 +9,7 @@
"Modules\\Portfolio\\Providers\\PortfolioServiceProvider",
"Modules\\Portfolio\\Providers\\RouteServiceProvider"
],
"aliases": {},
"files": [

],
"aliases": [],
"files": [],
"requires": []
}
}

0 comments on commit 87b3026

Please sign in to comment.