Slug/permalink field

The table to use slug must have column name. It's used to generate slug column.

Add slug/permalink field to your new plugin

- Open /plugins/<your-plugin>/src/Providers/<YourPlugin>ServiceProvider.php. Add below code to function boot

\SlugHelper::setPrefix(YourPluginModel::class, 'your-prefix');

// "your-prefix" is prefix for your slug field. URL will be http://domain.local/your-prefix/slug-here

- If you're using form builder to generate forms for your plugin, slug field will be added to your form automatically. If you don't use form builder. To add slug field, use bellow code.

For creating form:

<div class="form-group @if ($errors->has('slug')) has-error @endif">
    {!! Form::permalink('slug', old('slug'), 0, 'your-prefix') !!}
    {!! Form::error('slug', $errors) !!}

For editing form:

<div class="form-group @if ($errors->has('slug')) has-error @endif">
    {!! Form::permalink('slug', $data->slug, $data->id, \SlugHelper::getPrefix(YourPluginModel::class)) !!}
    {!! Form::error('slug', $errors) !!}

- Finally, you need to add a route to handle when users visit http://domain.local/your-prefix/slug-here

Example for route:

Route::group(apply_filters(BASE_FILTER_GROUP_PUBLIC_ROUTE, []), function () {

    Route::get(\SlugHelper::getPrefix(YourPluginModel::class) . '/{slug}, [
        'uses' => '[email protected]',


Example for controller method:

public function getBySlug($slug, \Botble\Slug\Repositories\Interfaces\SlugInterface $slugRepository)
    $slug = $slugRepository->getFirstBy(['key' => $slug, 'reference_type' => YourModel::class]);

    if (!$slug) {

    $data = $this->{yourPlugin}Repository->getFirstBy(['id' => $slug->reference_id]);

    if (!$data) {


    return Theme::scope('your-example-view', compact('data'))->render();