PHPackages                             taffovelikoff/laravel-sef - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. taffovelikoff/laravel-sef

ActiveLibrary[Search &amp; Filtering](/categories/search)

taffovelikoff/laravel-sef
=========================

Search engine friendly URLs for your laravel app.

v1.0.1(6y ago)12401MITPHPCI failing

Since Mar 3Pushed 6y ago2 watchersCompare

[ Source](https://github.com/TaffoVelikoff/laravel-sef)[ Packagist](https://packagist.org/packages/taffovelikoff/laravel-sef)[ Docs](https://github.com/TaffoVelikoff/laravel-sef)[ RSS](/packages/taffovelikoff-laravel-sef/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (1)Versions (3)Used By (1)

TaffoVelikoff/LaravelSef
========================

[](#taffovelikofflaravelsef)

🔗 Search engine friendly urls for your Laravel website.

Contents
--------

[](#contents)

[🤔 Why use it?](#why-use-it)

[💻 Requirements](#usage)

[⚙️ Installation](#installation)

[📚 Usage](#usage)

Why use it?
-----------

[](#why-use-it)

There are many ways to create search engine friendly urls. For example you can use "slugs":

-  - SEF url for a page model
-  - SEF url for a product model
-  - SEF url for a user model

What if you want to loose the prefix and have this instead:

-  - a page
-  - a product
- [https://mylaravel.com/john\_doe](https://mylaravel.com/john_doe) - a user

This package will help you achieve that!

Requirements
------------

[](#requirements)

> This package requires ***Laravel 5.8*** or above.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require taffovelikoff/laravel-sef
```

Don't forget to run the migrations. There is a migration file for a "sefs" table, where all the custom urls will be stored.

```
php artisan migrate
```

Usage
-----

[](#usage)

### 👉 STEP 1: Add the HasSef trait to a model

[](#-step-1-add-the-hassef-trait-to-a-model)

First, you need to add the TaffoVelikoff\\LaravelSef\\Traits\\HasSef trait to your model.

```
namespace App;

use TaffoVelikoff\LaravelSef\Traits\HasSef;
use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    use HasSef;
}
```

### 👉 STEP 2: Create/update the SEF

[](#-step-2-createupdate-the-sef)

```
namespace App\Http\Controllers\Admin;

use App\Product;
use Illuminate\Http\Request;

class ProductController extends Controller
{
    // Create a product
    public function store() {

        // Validate the request and make sure the "sef" keyword is unique.

        // Create
        $prod = Product::create([
            'name'  => 'My product',
            'price' => 2500
        ]);

        // Model to be available on https://mylaravel.com/my_product
        $product->createSef('my_product');

        return redirect()->back();
    }

    // Update a product
    public function update($id) {
        // Get the product
        $product = Product::findOrFail($id);

        // Update to be available on https://mylaravel.com/my_new_url
        $product->updateSef('my_new_url');

        return redirect()->back();
    }
}
```

Now you can use the sefUrl() method to link the resource in your templates:

```
{{ $product->name }}
```

### 👉 STEP 3: Call the right controller and method

[](#-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.

[](#️-method-1-url-mappings-in-config-file)

Publish the configuration file:

```
php artisan vendor:publish --tag:sef_config
```

Add this to your routes file (typically web.php) at the ***VERY BOTTOM***.

```
Route::get('{keyword}', '\TaffoVelikoff\LaravelSef\Http\Controllers\SefController@viaConfig');
```

Say you are trying to reach ****.

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:

```
// config/sef.php

return [

    'routes' => [
        'App\Product' => [ // The owner model type
            'controller' => 'App\Http\Controllers\ProductController', // controller, that handles the request
            'method' => 'index' // the method to view (show) the model
        ],
    ]

];
```

#### ▶️ Method 2: Define a $sef\_method property in the model

[](#️-method-2-define-a-sef_method-property-in-the-model)

Add this to your routes file (typically web.php) at the ***VERY BOTTOM***.

```
Route::get('{keyword}', '\TaffoVelikoff\LaravelSef\Http\Controllers\SefController@viaMethod');
```

Say you are trying to reach ****.

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:

```
namespace App;

use TaffoVelikoff\LaravelSef\Traits\HasSef;
use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    use HasSef;

    // Controller@method to view/show the model.
    public static $sef_method = 'App\Http\Controllers\ProductController@index';
}
```

In this example "App\\Http\\Controllers\\ProductController@index" is the controller and method used to view/show the model.

```
namespace App\Http\Controllers;

use App\Product;
use Illuminate\Http\Request;

class ProductController extends Controller
{
    // Show the model
    public function index($id) {
        // Get the product
        $prod = Product::findOrFail($id);

        // Display template
        return view('product');
    }
}
```

#### ▶️ Method 3: Your own controller

[](#️-method-3-your-own-controller)

Add this to your routes file (typically web.php) at the ***VERY BOTTOM***.

```
Route::get('{keyword}', 'App\MySefController@redirect');
```

Create your own controller:

```
namespace App\Http\Controllers;

use TaffoVelikoff\LaravelSef\Sef;
use App\Http\Controllers\Controller;

class SefController extends Controller
{

    // Redirect to right controller and method via the mapping in config
    public function redirect($keyword) {

        // Find SEF with keyword
        $sef = Sef::where('keyword', $request->route()->parameters['keyword'])->first();

        // Add your own code
        //return app()->call(..., ['id' => $sef->model_id]);
    }
}
```

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT](https://choosealicense.com/licenses/mit/) license.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

2261d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/86d23287dea7486112423331540e81c17c9b7fb3f79c43c7410505af4961572c?d=identicon)[TaffoVelikoff](/maintainers/TaffoVelikoff)

---

Top Contributors

[![TaffoVelikoff](https://avatars.githubusercontent.com/u/20744689?v=4)](https://github.com/TaffoVelikoff "TaffoVelikoff (12 commits)")

### Embed Badge

![Health badge](/badges/taffovelikoff-laravel-sef/health.svg)

```
[![Health](https://phpackages.com/badges/taffovelikoff-laravel-sef/health.svg)](https://phpackages.com/packages/taffovelikoff-laravel-sef)
```

###  Alternatives

[ruflin/elastica

Elasticsearch Client

2.3k50.4M203](/packages/ruflin-elastica)[opensearch-project/opensearch-php

PHP Client for OpenSearch

15024.3M65](/packages/opensearch-project-opensearch-php)[mailerlite/laravel-elasticsearch

An easy way to use the official PHP ElasticSearch client in your Laravel applications.

934529.3k2](/packages/mailerlite-laravel-elasticsearch)[massive/search-bundle

Massive Search Bundle

721.4M13](/packages/massive-search-bundle)[outl1ne/nova-multiselect-filter

Multiselect filter for Laravel Nova.

45802.7k3](/packages/outl1ne-nova-multiselect-filter)[handcraftedinthealps/zendsearch

a general purpose text search engine written entirely in PHP 5

39921.0k35](/packages/handcraftedinthealps-zendsearch)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
