PHPackages                             royvoetman/laravel-prefixer - 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. [Templating &amp; Views](/categories/templating)
4. /
5. royvoetman/laravel-prefixer

ActiveLibrary[Templating &amp; Views](/categories/templating)

royvoetman/laravel-prefixer
===========================

Define a prefix in your controller which is automatically appended to your view- or route-names.

v1.0.4(2y ago)217MITPHPPHP ^7.2 || ^8.0CI failing

Since Oct 27Pushed 2y ago1 watchersCompare

[ Source](https://github.com/RoyVoetman/laravel-prefixer)[ Packagist](https://packagist.org/packages/royvoetman/laravel-prefixer)[ RSS](/packages/royvoetman-laravel-prefixer/feed)WikiDiscussions master Synced yesterday

READMEChangelog (5)Dependencies (3)Versions (6)Used By (0)

Laravel Prefixer
================

[](#laravel-prefixer)

Introduction
------------

[](#introduction)

This packages allows you to define a prefix in your controller which will be automatically appended to your view and/or route names.

In a resource controller, it is a common pattern to have all the associated views in the same folder, and the same goes for the location of your routes. With this feature, you can define a prefix which is automatically appended to your view-name or route-name.

[![Latest Version](https://camo.githubusercontent.com/08906f03057abf26afa717a5ad9fcee544ecb0281605806885d1c79b9e4cbc91/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f79766f65746d616e2f6c61726176656c2d70726566697865722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/royvoetman/laravel-prefixer)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Total Downloads](https://camo.githubusercontent.com/b5b060085dff8b640513e367b51fcbb703c37947e269c4c3e6499216d70aeddf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f79766f65746d616e2f6c61726176656c2d70726566697865722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/royvoetman/laravel-prefixer)

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

[](#installation)

```
composer require royvoetman/laravel-prefixer
```

View prefixes
-------------

[](#view-prefixes)

When you want to use View prefixes your controller will have to implement the `RoyVoetman\Prefixer\Contracts\ViewPrefix` interface. This interface requires you to add a `viewPrefix` method that returns a `string`.

Second your Controller must include the `RoyVoetman\Prefixer\Http\Traits\CreatesViews` trait. This trait includes the `view(string $view)` method to the controller which handles the prefixing for us. The best practice is to include this trait in your `BaseController` . This method checks if the `CreatesViews` interface is implemented, if this is not the case this method will behave the same as the `view()` global helper function.

```
namespace App\Http\Controllers;

use Illuminate\Contracts\Support\Renderable;
use RoyVoetman\Prefixer\Contracts\ViewPrefix;
use RoyVoetman\Prefixer\Http\Traits\CreatesViews;

/**
 * Class BookController
 *
 * @package App\Http\Controllers
 */
class BookController extends Controller implements ViewPrefix
{
    use CreatesViews;

    /**
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function create(): Renderable
    {
      	// Return view: `authorized.books.create`
        return $this->view('create');
    }

    /**
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function edit(Book $book): Renderable
    {
      	// You can have chain methods like `with()` just like
      	// you normally would when using `return view()`
        return $this->view('edit')->with('book', $book);
    }

    /**
     * @return string
     */
    public function viewPrefix(): string
    {
        return 'authorized.books';
    }
}
```

Route prefixes
--------------

[](#route-prefixes)

Route prefixing works the same as View Prefixing except for the following:

The Controller must implement the `RoyVoetman\Prefixer\Contracts\RoutePrefix` interface and must include the `RoyVoetman\Prefixer\Http\Traits\ForwardsRequests` trait.

Instead of the `viewPrefix` method, you have to include a `routePrefix` method. And instead of the `view(string $view)` method you have to use the `redirect(string $route)` method. When the `RoutePrefix` method is not implemented this method will behave the same as calling `redirect()->route($route)`.

> Route prefixes only work if you are using [named routes](https://laravel.com/docs/5.8/routing#named-routes).

```
namespace App\Http\Controllers;

use Illuminate\Http\RedirectResponse;
use RoyVoetman\Prefixer\Contracts\RoutePrefix;
use RoyVoetman\Prefixer\Http\Traits\ForwardsRequests;

/**
 * Class BookController
 *
 * @package App\Http\Controllers
 */
class BookController extends Controller implements RoutePrefix
{
    use ForwardsRequests;

    /**
     * @return \Illuminate\Http\RedirectResponse
     */
    public function store(): RedirectResponse
    {
	...

        // Redirect to: `books.index`
        return $this->redirect('index');
    }

    /**
     * @return \Illuminate\Http\RedirectResponse
     */
    public function update(Book $book): RedirectResponse
    {
        ...

      	// You can have chain methods like `with()` just like
      	// you normally would when using `return redirect()`
        return $this->redirect('index')->with('status', 'Book updated');
    }

    /**
     * @return string
     */
    public function routePrefix(): string
    {
        return 'books';
    }
}
```

View and Route prefixes
-----------------------

[](#view-and-route-prefixes)

There is a convenient shortcut when you want to implement the `ViewPrefix` and the `RoutePrefix` interface. You can include the `RoyVoetman\Prefixer\Contracts\ResponsePrefixes` interface which just extends both interfaces.

```
/**
 * Interface ResponsePrefixes
 *
 * @package App\Interfaces
 */
interface ResponsePrefixes extends RoutePrefix, ViewPrefix
{
    //
}
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Contributions are **welcome** and will be fully **credited**. We accept contributions via Pull Requests on [Github](https://github.com/RoyVoetman/laravel-prefixer).

### Pull Requests

[](#pull-requests)

- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
- **Create feature branches** - Don't ask us to pull from your master branch.
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity66

Established project with proven stability

 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 ~331 days

Total

5

Last Release

1061d ago

PHP version history (2 changes)v1.0.0PHP ^7.2

v1.0.3PHP ^7.2 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/23026444?v=4)[Roy Voetman](/maintainers/RoyVoetman)[@RoyVoetman](https://github.com/RoyVoetman)

---

Top Contributors

[![RoyVoetman](https://avatars.githubusercontent.com/u/23026444?v=4)](https://github.com/RoyVoetman "RoyVoetman (15 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/royvoetman-laravel-prefixer/health.svg)

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

###  Alternatives

[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

44643.1k1](/packages/pressbooks-pressbooks)[livewire/blaze

A tool for optimizing Blade component performance by folding them into parent templates

688221.3k17](/packages/livewire-blaze)[laravellux/html

HTML and Form Builders for the Laravel Framework

35239.2k3](/packages/laravellux-html)[konekt/html

HTML and Form Builders for the Laravel Framework

24403.2k5](/packages/konekt-html)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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