Skip to content

Commit

Permalink
enhance url generator to handle non attribute_data
Browse files Browse the repository at this point in the history
  • Loading branch information
wychoong committed Feb 15, 2023
1 parent f36338a commit 8073663
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions packages/core/src/Generators/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,15 @@ public function __construct()
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
*/
public function handle(Model $model)
public function handle(Model $model, $attribute = 'name')
{
$this->model = $model;

if (! $model->urls->count()) {
if ($model->attribute_data) {
return $this->createUrl(
$model->attr('name')
);
}

if ($name = $model->name) {
return $this->createUrl($name);
return $this->createFromAttribute($attribute);
} elseif ($model->{$attribute}) {
return $this->generateSlug($model->{$attribute});
}
}
}
Expand All @@ -59,7 +55,12 @@ public function handle(Model $model)
* @param string $attribute
* @return void
*/
protected function createUrl($value)
protected function createFromAttribute($attribute)
{
$this->generateSlug($this->model->translateAttribute($attribute));
}

protected function generateSlug($value)
{
$slug = Str::slug($value);

Expand Down

0 comments on commit 8073663

Please sign in to comment.