Download the PHP package taffovelikoff/laravel-sef without Composer
On this page you can find all versions of the php package taffovelikoff/laravel-sef. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download taffovelikoff/laravel-sef
More information about taffovelikoff/laravel-sef
Files in taffovelikoff/laravel-sef
Package laravel-sef
Short Description Search engine friendly URLs for your laravel app.
License MIT
Homepage https://github.com/TaffoVelikoff/laravel-sef
Informations about the package laravel-sef
TaffoVelikoff/LaravelSef
🔗 Search engine friendly urls for your Laravel website.
Contents
🤔 Why use it?
💻 Requirements
⚙️ Installation
📚 Usage
Why use it?
There are many ways to create search engine friendly urls. For example you can use "slugs":
- https://mylaravel.com/pages/my-custom-url - SEF url for a page model
- https://mylaravel.com/products/my-custom-url - SEF url for a product model
- https://mylaravel.com/products/user-name - SEF url for a user model
What if you want to loose the prefix and have this instead:
- https://mylaravel.com/history - a page
- https://mylaravel.com/vans - a product
- https://mylaravel.com/john_doe - a user
This package will help you achieve that!
Requirements
This package requires Laravel 5.8 or above.
Installation
You can install the package via composer:
Don't forget to run the migrations. There is a migration file for a "sefs" table, where all the custom urls will be stored.
Usage
👉 STEP 1: Add the HasSef trait to a model
First, you need to add the TaffoVelikoff\LaravelSef\Traits\HasSef trait to your model.
👉 STEP 2: Create/update the SEF
Now you can use the sefUrl() method to link the resource in your templates:
👉 STEP 3: Call the right controller and method
You have a few options on how to call the controller and method used to view the model.
▶️ Method 1: URL mappings in config file.
Publish the configuration file:
Add this to your routes file (typically web.php) at the VERY BOTTOM.
Say you are trying to reach https://mylaravel.com/something.
If /something is not defined in your app routes SefController@viaConfig will be called. This method will search in the "sefs" table for a record where keyword = 'something'.
If no such record exists a 404 error will be thrown.
If the record is found the method will check if the owner model type (class) exists in the routes array in config/sef.php:
▶️ Method 2: Define a $sef_method property in the model
Add this to your routes file (typically web.php) at the VERY BOTTOM.
Say you are trying to reach https://mylaravel.com/something.
If /something is not defined in your app routes SefController@viaMethod will be called. This method will search in the "sefs" table for a record where keyword = 'something'.
If no such record exists a 404 error will be thrown.
If the record is found the method will next check what is the owner model type. Say the owner model is of type "App\Product". Next the method will check for a public static property $sef_method in the App\Product model:
In this example "App\Http\Controllers\ProductController@index" is the controller and method used to view/show the model.
▶️ Method 3: Your own controller
Add this to your routes file (typically web.php) at the VERY BOTTOM.
Create your own controller:
License
This package is open-sourced software licensed under the MIT license.