Good morning!
If I understood correctly what your doubts were:
Relationships, in laravel, are stored in models.
Model Book, for example:
public function user()
{
$this->belongsTo('User');
}
If you want the entire relationship to be called, you have to retrieve one or more books from the database, you can use the with attribute of the Eloquent \ Model:
protected $with = ['user'];
where 'user' is the name given in the above method.
Laravel has a great permissions management, so you could define more rules in the User model, like:
public function isAdmin ()
{
return ($ this-> isAdmin == true);
}
So you can check if the user is admin anywhere in 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 the constraints:
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)
);
This way you could perform a eager loading
to determine whether a user has permission to access a particular location, along with the addition of filters that do this automatically.
Packages are meant 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 inside / app called library and add it 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 inside this folder, you must use the namespace separation.
A good example is the open source laravel-tricks .