for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\Http\Controllers\Admin;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use App\Models\UserRole;
class UserCrudController extends CrudController
{
public function setup()
$this->crud->setModel("App\Models\User");
$this->crud->setRoute("admin/user");
$this->crud->setEntityNameStrings('user', 'users');
$this->crud->denyAccess('create');
$this->crud->denyAccess('delete');
$this->crud->addColumn([
'name' => 'name',
'type' => 'text',
'label' => 'Name'
]);
If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:
someFunctionCall( $firstArgument, $secondArgument, $thirdArgument ); // Closing parenthesis on a new line.
'name' => 'email',
'label' => 'Email'
'name' => 'user_role.name',
'label' => 'Role'
$this->crud->addFilter([
'name' => 'user_role',
'type' => 'select2',
], function () {
return UserRole::all()->keyBy('id')->pluck('name', 'id')->toArray();
}, function ($value) {
$this->crud->addClause('where', 'user_role_id', $value);
});
$this->crud->addField([
'label' => "Name",
'attributes' => [
'readonly'=>'readonly'
]
'label' => "Role",
'type' => 'select',
'name' => 'user_role_id', // the db column for the foreign key
'entity' => 'user_role', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => "App\Models\UserRole" // foreign key model
}
public function update($request)
$request
If this is a false-positive, you can also ignore this issue in your code via the ignore-unused annotation
ignore-unused
public function update(/** @scrutinizer ignore-unused */ $request)
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
$response = parent::updateCrud();
return $response;