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',
]);
}
}