PHP code example of figlabhq / crud-resource-for-backpack
1. Go to this page and download the library: Download figlabhq/crud-resource-for-backpack library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
figlabhq / crud-resource-for-backpack example snippets
declare(strict_types=1);
namespace App\CrudResources;
use FigLab\CrudResource\CrudResource;
use App\Models\User;
use FigLab\CrudResource\Fields\Email;
use FigLab\CrudResource\Fields\Password;
use FigLab\CrudResource\Fields\Select;
use FigLab\CrudResource\Fields\Text;
class UserCrudResource extends CrudResource
{
public function fields(): array
{
return [
Text::make('Name')
->sortable(),
Email::make('Email'),
Password::make('Password')
->size(6)
->onlyOnForms(),
Password::make('Confirm Password', 'password_confirmation')
->size(6)
->onlyOnForms(),
];
}
}
declare(strict_types=1);
namespace App\Http\Controllers;
use App\CrudResources\User\UserCrudResource;
class UserCrudController extends CrudController
{
private UserCrudResource $crudResource;
public function setup()
{
$this->crud->setModel(\App\Models\User::class);
$this->crud->setRoute(config('backpack.base.route_prefix') . '/users');
$this->crud->setEntityNameStrings('user', 'users');
$this->crudResource = new UserCrudResource($this->crud);
}
protected function setupListOperation(): void
{
$this->crudResource->buildList();
}
protected function setupCreateOperation(): void
{
$this->crud->setValidation(UserStoreRequest::class);
$this->crudResource->buildCreateForm();
}
protected function setupUpdateOperation(): void
{
$this->crud->setValidation(UserUpdateRequest::class);
$this->crudResource->buildUpdateForm();
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.