2017 © Pedro Peláez
 

library cmsbasics

A package for Laravel, which I use to build repetitive resource Items.

image

alexwenzel/cmsbasics

A package for Laravel, which I use to build repetitive resource Items.

  • Tuesday, October 7, 2014
  • by alexwenzel
  • Repository
  • 1 Watchers
  • 1 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

my cms basics for laravel

A package for Laravel, which I use to build repetitive resource Items., (*1)

Model

Create a model for your new resource item., (*2)

The resource model should have a static $rules property, which contain all resource rules., (*3)

class Post extends \Eloquent {

  protected $table = 'posts';
  protected $fillable = ['title', 'body'];

  public static $rules = [
    'title' => 'required',
    'body' => 'required',
  ];
}

Controller

Create a new controller by extending the base resource controller. In the constructor you can specify some settings., (*4)

  • dependency => your resource item's model
  • resource_name => the identifier of your resource, the one you use at Route::resource()
  • view_dir => path to the rescource views
use Alexwenzel\Cmsbasics\Controllers\Resource;

class PostsController extends Resource {

  public function __construct(Post $model)
  {
    parent::__construct([
      'dependency'    => $model,
      'resource_name' => 'posts',
      'view_dir'      => 'path.to.views',
    ]);
  }
}

Then register the controller in your routes., (*5)

Route::resource('posts', 'PostsController');

Customize behaviour

You cann customize the behaviour of the base resource controller by overriding specific methods, (*6)

protected function _index_items()
protected function _store_data()
protected function _store_validator($data)
protected function _store_fails($data, $validator)
protected function _store_finished($data, $model)
protected function _update_data()
protected function _update_validator($id, $data)
protected function _update_fails($data, $model, $validator)
protected function _update_finished($data, $model)
protected function _destroy_finished()

Events

The following Events are fired within the base resource controller:, (*7)

index, (*8)

[resource_name].index

create, (*9)

[resource_name].create

store, (*10)

[resource_name].store

Passes the newly created resource as the first argument., (*11)

show, (*12)

[resource_name].show

Passes the requested resource as the first argument., (*13)

edit, (*14)

[resource_name].edit

Passes the requested resource as the first argument., (*15)

update, (*16)

[resource_name].update

Passes the updated resource as the first argument., (*17)

destroy, (*18)

[resource_name].destroy

View

This package comes with default views for all actions (index, create, show, edit). Publish the package views as a starting point., (*19)

php artisan view:publish alexwenzel/cmsbasics

Copy the package views to a new folder and customize them., (*20)

class PostsController extends Resource {

  public function __construct(Post $model)
  {
    parent::__construct([
      'dependency'    => $model,
      'resource_name' => 'posts',
      'view_dir'      => 'path.to.views',
    ]);
  }
}

The Versions

07/10 2014

dev-development

dev-development

A package for Laravel, which I use to build repetitive resource Items.

  Sources   Download

The Requires

 

by Avatar alexwenzel

laravel resource controller resource item

07/10 2014

0.0.1-beta

0.0.1.0-beta

A package for Laravel, which I use to build repetitive resource Items.

  Sources   Download

The Requires

 

by Avatar alexwenzel

laravel resource controller resource item