Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.2] Hotfix - Brand url generation #862

Merged
merged 15 commits into from
Feb 15, 2023
Prev Previous commit
Next Next commit
Revert "enhance url generator to handle non attribute_data"
This reverts commit 8073663.
  • Loading branch information
wychoong committed Feb 15, 2023
commit 3cb59c4477318290efc3c0e0f0d475a69e9ac8de
19 changes: 9 additions & 10 deletions packages/core/src/Generators/UrlGenerator.php
Original file line number Diff line number Diff line change
@@ -36,15 +36,19 @@ public function __construct()
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
*/
public function handle(Model $model, $attribute = 'name')
public function handle(Model $model)
{
$this->model = $model;

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

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

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