Global slug for models #2090
MDylan
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I want to introduce you my solution if you need global slugs for each modules (or just 2-3 module).
Example:
I don't want to use different path for Pages, Products.
In default, permalink based on this: /page/{slug} or /product/{slug}
But I want one slug database for this two models and hide "module" from url. How can I do this?
Solution tried on Twill 2.12.4
First, you need to create a model:
php artisan make:model GlobalSlug -m
Modify the fillable variable App\Modules\GlobalSlug.php file
And need modify migration file:
Run php artisan migrate
Than in the App\Models\Slugs\PageSlug.php and App\Models\Slugs\ProductSlug.php file, you need to modify $table variable:
After that, modify App\Http\Controllers\Admin\PageController.php and App\Http\Controllers\Admin\ProductController.php file
And after that, you need to add some modified code to Models. Example to App\Models\Page.php and App\Models\Product.php
At this step, you can create slugs for Pages and Products in database.
Now, how can we show this on frontend?
Example:
Make a Controller file, in my case: PathsController.php
If you see, you need to create default site.page.show blade file. Or if you want to use different by models, you can do it.
Example create site.product.show and it will be use that!
Now, only you need create route for PathsController in the routes/web.php file.
I hope it will be usefull somebody too and if you have any suggestion, please tell me.
Beta Was this translation helpful? Give feedback.
All reactions