Package Data | |
---|---|
Maintainer Username: | bryannielsen |
Maintainer Contact: | bryan@packettide.com (Bryan Nielsen) |
Package Create Date: | 2013-10-22 |
Package Last Update: | 2014-03-25 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-23 03:28:13 |
Package Statistics | |
---|---|
Total Downloads: | 284 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 15 |
Total Watchers: | 4 |
Total Forks: | 2 |
Total Open Issues: | 0 |
#Bree
Bree provides an interface to associate fieldtypes with existing Eloquent model attributes.
This project is still in an early stage and breaking changes may be made.
##Installation
With Laravel 4 and Composer
"packettide/bree": "1.x"
to your 'require' block in composer.jsoncomposer update
'Packettide\Bree\BreeServiceProvider',
to the $providers array in app/config/app.phpphp artisan bree:assets
##Basic Usage
In this section we'll cover the fundamentals of how to interact with Bree. Bree functions by wrapping an existing Eloquent model and attaching field definitions to model attributes.
$book = new Bree('Book', array(
'title' => array('type' => 'Text')
));
In app/models/Book.php
<?php
class Book extends Eloquent {
public $breeFields = array(
'title' => array('type' => 'Text')
);
Note that you can define a base field mapping in your model and override fields in a route if desired.
$book = new Bree('Book');
echo $book; //this will output fields for all defined attributes
$book = new Bree('Book');
$book->find(1);
echo $book;
If you don't wish to display all Bree fields from a model or would like to control the order you can use the model attributes in your views like so:
// Route
$book = new Bree('Book');
return View::make('books.create', array('book' => $book));
// View
{{ $book->title }} // this will output the label if available, followed by the field
{{ $book->title->field() }} // outputs the field only
{{ $book->title->label() }} // outputs the label only
$input = Input::except('_token');
$book = new Bree('Book');
foreach($input as $key => $value)
{
$book->$key = $value;
}
$book->save();
Here is an example of what a field definition looks like:
array('comments' => array('type' => 'Relate', 'label' => 'Book Comments', 'related' => 'Comment', 'title' => 'title'))
The following field types are available by default:
Adding another field package to your project typically involves adding the dependency to your composer.json file and registering the service provider with your application. Here are a few field packages which have more detailed instructions on their project pages:
While Bree is a simple layer to add over an existing Eloquent model you may find it tedious to setup the mapping of fields to attributes and model relations etc… We have another package called Sire, which helps alleviate this problem while also providing a simple way to scaffold an application with Bootstrap 3.
Bree is built to be a flexible and extensible base allowing for the creation of field types as they are required by a project. To learn more about creating your own field package start here.
Bree is open-sourced software licensed under the MIT license