PHPackages                             webtack/generic-controller - 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. webtack/generic-controller

ActiveLibrary

webtack/generic-controller
==========================

Generic Controllers includes a set of generic representations that are ideally suited for solving a number of routine tasks.

v1.1.0(8y ago)1132MITPHPPHP &gt;=7.0.0

Since Mar 4Pushed 8y agoCompare

[ Source](https://github.com/webtack/generic-controller)[ Packagist](https://packagist.org/packages/webtack/generic-controller)[ Docs](https://github.com/webtack/generic-controller)[ RSS](/packages/webtack-generic-controller/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (9)DependenciesVersions (11)Used By (0)

Generic Controllers
===================

[](#generic-controllers)

Generic Controllers is a extension system for your [Laravel](https://laravel.com) application.
Generic Controllers includes a set of generic representations that are ideally suited for solving a number of routine tasks.

Installation
============

[](#installation)

Install using composer:

```
composer require webtack/generic-controller

```

Simple examples
===============

[](#simple-examples)

Use Generic as the parent classes. You can specify these classes as the parent for your custom view class and override the attribute values in the body of your class

TemplateController
------------------

[](#templatecontroller)

Suitable for displaying static pages that do not receive data from the database.

```
use Webtack\GenericController\TemplateController;

class AboutController extends TemplateController {

	/**
	 * Init templateName property from view
	 *
	 * @return string
	 */
	function templateName() {
		return "generic-about";
	}
}
```

Create a router and call the method in it @asView

```
Route::get(/about', ['uses' => 'AboutController@asView']);
```

DetailController
----------------

[](#detailcontroller)

It should be used when you want to get one model for a given key

```
use App\Models\Article;
use Webtack\GenericController\DetailController;

class ArticlePageController extends DetailController {

	/**
	 * Init Model from Query
	 *
	 * @return \Illuminate\Database\Config\Model
	 */
	function model() {
		return new Article();
	}
}
```

Create a router and call the method in it @asView

```
Route::get(/article/{id}', ['uses' => 'ArticlePageController@asView']);
```

### Context data

[](#context-data)

```
    protected function getContextData($request, $column = []){}
```

The method responsible for obtaining data from the database.
By default, there will be an attempt to get the model by the parameter **id** from the route

But you can override this behavior by overloading this method. It must return an array with a context name key and an object of the model.

```
protected function getContextData($request, $column = []) {
    $article = $this->model();
    $data = $article->where(['name' => 'Jhoon'])->first();

    return ['article' => $data];
}
```

Or override get method

```
public function get($request, $name) {
	$context = $this->getContextData($request, ['name' => $name]);
	return $this->renderToResponse($context);
}
```

Supported methods correspond to request types.

```
    public function get($request);
    public function post($request);
    public function put($request);
    public function delete($request);
    public function path($request);
    public function options($request);
```

All methods accept the first object **\\Illuminate\\Http\\Request $request**The following parameters can be those that you defined in your routes.

### View Name

[](#view-name)

By default, DetailController will search for a view with the name of the "article-page" class new, and you will also be able to override it in the **templateName** method

Note the auxiliary methods **templatePrefix** and **templateSuffix**.
If you define them, the data will be appended to the name of the view returned by the method **templateName**

### Context name

[](#context-name)

The name of the access variable in the view will be taken from the name of the model class starting with a small letter.

```
{{ $article->title }}
```

Of course you can override this in method **contextObjectName**

```
protected function contextObjectName() {
    return "foobar";
}
```

ListController
--------------

[](#listcontroller)

Use to display the list of entities

```
use Webtack\GenericController\ListController;

class BlogPageController extends ListController {

	/**
	 * @return \Illuminate\Database\Config\Model
	 */
	public function model() {
		return new Blog();
	}

	/**
	 * Init templateName from view
	 *
	 * @return string
	 */
	public function templateName() {
		return 'blog';
	}

	protected function templatePrefix() {
		return 'blog.';
	}
}
```

Create a router and call the method in it @asView

```
Route::get(/blog', ['uses' => 'BlogPageController@asView']);
```

By default, the name of the view will be appended with the suffix **- list**, but you can undo or override this behavior in the corresponding method, of course.

P.S.
----

[](#ps)

This is a small set of possibilities. But I think in the future I will expand it if necessary.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity64

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

Total

8

Last Release

2965d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/87845ad59eab9a5a61db06376b9f0cf125ac8d99badb0b84102cab4d468a3952?d=identicon)[webtack](/maintainers/webtack)

---

Top Contributors

[![webtack](https://avatars.githubusercontent.com/u/36098458?v=4)](https://github.com/webtack "webtack (43 commits)")

---

Tags

laravelcontrollergenericwebtack

### Embed Badge

![Health badge](/badges/webtack-generic-controller/health.svg)

```
[![Health](https://phpackages.com/badges/webtack-generic-controller/health.svg)](https://phpackages.com/packages/webtack-generic-controller)
```

###  Alternatives

[lorisleiva/laravel-actions

Laravel components that take care of one specific task

2.8k7.5M115](/packages/lorisleiva-laravel-actions)[phpsa/laravel-api-controller

A laravel api base controller with basic CRUD mapped to the model

4860.6k5](/packages/phpsa-laravel-api-controller)[d-scribe/laraquick

A collection of classes to be extended/used in laravel applications for quick development

371.8k1](/packages/d-scribe-laraquick)[mallardduck/laravel-traits

A collection of useful Laravel snippets in the form of easy to use traits.

136.2k2](/packages/mallardduck-laravel-traits)[opanegro/nova-custom-controller

Make custom controller in Laravel Nova

144.4k](/packages/opanegro-nova-custom-controller)

PHPackages © 2026

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