2017 © Pedro Peláez
 

library generic-controller

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

image

webtack/generic-controller

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

  • Monday, April 2, 2018
  • by webtack
  • Repository
  • 0 Watchers
  • 0 Stars
  • 22 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 11 Versions
  • 29 % Grown

The README.md

Generic Controllers

Generic Controllers is a extension system for your Laravel application.
Generic Controllers includes a set of generic representations that are ideally suited for solving a number of routine tasks., (*1)

Installation

Install using composer:, (*2)

composer require webtack/generic-controller

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, (*3)

TemplateController

Suitable for displaying static pages that do not receive data from the database., (*4)


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, (*5)

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

DetailController

It should be used when you want to get one model for a given key, (*6)


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, (*7)

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

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, (*8)

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., (*9)

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

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

Or override get method, (*10)

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

Supported methods correspond to request types., (*11)


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., (*12)

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, (*13)

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, (*14)

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., (*15)

{{ $article->title }}

Of course you can override this in method contextObjectName, (*16)

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

ListController

Use to display the list of entities, (*17)


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, (*18)

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., (*19)

P.S.

This is a small set of possibilities. But I think in the future I will expand it if necessary., (*20)

The Versions

02/04 2018

dev-master

9999999-dev https://github.com/webtack/generic-controller

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

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

laravel generic controller webtack

02/04 2018

v1.1.0

1.1.0.0 https://github.com/webtack/generic-controller

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

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

laravel generic controller webtack

01/04 2018

v1.0.9

1.0.9.0 https://github.com/webtack/generic-controller

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

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

laravel generic controller webtack

16/03 2018

v1.0.8

1.0.8.0 https://github.com/webtack/generic-controller

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

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

laravel generic controller webtack

05/03 2018

v1.0.7

1.0.7.0 https://github.com/webtack/generic-controller

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

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

laravel generic controller webtack

04/03 2018

1.0.6

1.0.6.0 https://github.com/webtack/generic-controller

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

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

laravel generic controller webtack

04/03 2018

dev-add-license-1

dev-add-license-1 https://github.com/webtack/generic-controller

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

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

laravel generic controller webtack

04/03 2018

v1.0.5

1.0.5.0 https://github.com/webtack/generic-controller

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

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

laravel generic controller webtack

04/03 2018

v1.0.4

1.0.4.0

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

laravel generic controller webtack

04/03 2018

v1.0.2.x-dev

1.0.2.9999999-dev

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

laravel generic controller webtack

04/03 2018

dev-v1.0.0-dev

dev-v1.0.0-dev

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

laravel generic controller webtack