Good morning!
If I understood correctly what your doubts were:
The relationships, in Standard, are stored in the models.
Model Book, for example:
public function user()
{
$this->belongsTo('User');
}
If you want the whole relationship to be called you have retrieved one or more books from the database, you can use the attribute with da model Eloquent Model:
protected $with = ['user'];
where 'user' is the name given in the above method.
Laravel has great permissions management, so you could set more rules in the User model, like:
public Function isAdmin()
{
Return ($this->isAdmin == true);
}
So you can check if the user is admin at any location of the application by just calling:
Auth::user()->isAdmin()
Following the same courses you can make more complex and flexible validations using a table to store rules or groups as well.
Example of permissions 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)
);
That way you could accomplish one Eager loading
to determine whether a user has permission to access a particular location, along with adding filters that do this automatically.
The packages aim to make the project more organized, flexible and reusable, so you can use them in other applications without much change. Its use is not necessary, but recommended for large applications.
Instead of building packages, you 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, namespace separation should be used.
A good example is open source Laravel-Tricks.
Well in my understanding, Books and Users are Entities of your application, not the packages. Your package would actually be just the Crud and the Authentication Module, where they consume the entity (or the Model).
– gmsantos