6
I’m studying the structure of the Laravel from this example already ready => beast.
In the project there is the repository userRepository with the following structure:
<?php
namespace App\Repositories;
use App\Models\User;
class UserRepository
{
    /**
     * Get users collection paginate.
     *
     * @param  int  $nbrPages
     * @param  array  $parameters
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
     */
    public function getAll($nbrPages, $parameters)
    {
        return User::with ('ingoing')
            ->orderBy ($parameters['order'], $parameters['direction'])
            ->when (($parameters['role'] !== 'all'), function ($query) use ($parameters) {
                $query->whereRole ($parameters['role']);
            })->when ($parameters['valid'], function ($query) {
                $query->whereValid (true);
            })->when ($parameters['confirmed'], function ($query) {
                $query->whereConfirmed (true);
            })->when ($parameters['new'], function ($query) {
                $query->has ('ingoing');
            })->paginate ($nbrPages);
    }
}
This structure makes use of the config file parameters:
<?php
return [
    'users' => [
        'order' => 'created_at',
        'direction' => 'desc',
        'role' => 'all',
        'valid' => false,
        'confirmed' => false,
        'new' => false,
    ],
    'posts' => [
        'order' => 'created_at',
        'direction' => 'desc',
        'new' => false,
        'active' => false,
    ],
    'contacts' => [
        'new' => false,
    ],
    'comments' => [
        'new' => false,
        'valid' => false,
    ],
];
The structure of the database is as follows:
Schema::create('users', function(Blueprint $table) {
    $table->increments('id');
    $table->timestamps();
    $table->string('name')->unique();
    $table->string('email')->unique();
    $table->string('password');
    $table->rememberToken();
    $table->enum('role', array('user', 'redac', 'admin'));
    $table->boolean('valid')->default(false);
});
I’m trying to understand these methods: whereRole, whereValid and whereConfirmed, I searched the entire project and I couldn’t find the structure of these methods, as Laravel puts together these methods?
Cool!! And in the case of a bank column that is id? How would I mount this Where?
whereRole_Id?– MarceloBoni
@Marceloboni How so?
roleis already a column.– Jéf Bueno
In this template already ready, they use
roleas a field In one, I think of decoupling and creating a new table in the bd, referencing only the role id, in this case the columnrolebecame:$table->integer('role_id')->unsigned();– MarceloBoni
@Marceloboni in this case you exchange the snake_case for Camel case. It would be
whereRoleId()– Jéf Bueno