D
Good morning!If I understood well what their doubts were:Relationships in laravel are stored in models.Model Book, for example:public function user()
{
$this->belongsTo('User');
}
If you want the relationship to be called all you have to recover one or more books from the database, you can use the attribute with the model Eloquent\Model:protected $with = ['user'];
where 'user' is the name given in the above method.Laravel has a great permission management, so you could set more rules in User model, such as:public function isAdmin()
{
return ($this->isAdmin == true);
)So you can check if the user is admin at any location of the application, just by calling:Auth::user()->isAdmin()Following the same courses you can make more complex and flexible validations using a table to store the rules or groups as well.Example of permission management used by Django in sqlite, without restrictions:CREATE TABLE `auth_user` (
`id` integer NOT NULL,
`password` varchar(128) NOT NULL,
`last_login` datetime NOT NULL,
`is_superuser` bool NOT NULL,
`group_id` integer NOT NULL,
`username` varchar(30) NOT NULL UNIQUE,
`first_name` varchar(30) NOT NULL,
`last_name` varchar(30) NOT NULL,
`email` varchar(75) NOT NULL,
`is_active` bool NOT NULL,
`date_joined` datetime NOT NULL,
PRIMARY KEY(id)
);
CREATE TABLE auth_permission (
id integer NOT NULL,
name varchar(50) NOT NULL,
content_type_id integer NOT NULL,
codename varchar(100) NOT NULL,
PRIMARY KEY(id)
);
CREATE TABLE auth_group_permissions (
id integer NOT NULL,
group_id integer NOT NULL,
permission_id integer NOT NULL,
PRIMARY KEY(id)
);
CREATE TABLE auth_group (
id integer NOT NULL,
name varchar(80) NOT NULL UNIQUE,
PRIMARY KEY(id)
);
In this way you could realize a http://laravel.com/docs/4.2/eloquent#eager-loading to determine if a user has permission to access certain location, along with adding filters that do so automatically.The packages aim to leave the project more organized, flexible and reusable, so that you can use them in other applications without many changes. Its use is not necessary, but recommended for large applications.Instead of building packages, it could create a folder within /app called library and add to composer. json:"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
],
"psr-0": {
"Biblioteca": "app/biblioteca"
}
},
In each script within this folder, one must use the separation by namespace.A good example is the open source of https://github.com/CodepadME/laravel-tricks .