Skip to content

Deprecated APIs and How To Replace Them ​

From 7.2, the classic module layer is deprecated in favour of resources and pages (the CrudBooster\ namespace). Everything listed here still works in every 7.x release: the deprecation is a @deprecated tag in the source, so your IDE and static analysis (PHPStan, Psalm) strike the calls through and show the replacement. Nothing is logged and nothing changes at runtime. The classes and functions may be removed in 8.0, no earlier.

For worked examples with before and after code, see Migrating A Module Step By Step.

Move at your own pace. Classic modules and resources share the login, layout, sidebar, privileges and audit log, so you can convert one module at a time.

What is not deprecated ​

These are shared by both layers and stay:

  • The models (crocodicstudio\crudbooster\models\*), migrations and cms_* tables.
  • The service contracts for authentication, permissions, settings, audit log, mail, notifications, schema, menus, uploads and privileges (contracts/Security, Settings, Audit, Mail, Notifications, Schema, Navigation, Files, Modules) and their implementations. These are the replacements for most CRUDBooster::* methods.
  • The built-in admin screens (users, privileges, menus, settings, logs, notifications, email templates), the CBBackend and CBAuthAPI middlewares, CBRouter and CBHook.
  • FCM, crudbooster:install, crudbooster:update and crudbooster:version.

Modules: CBController to Resource ​

DeprecatedReplacement
CBController and cbInit()CrudBooster\Resources\Resource with table() and form()
modern\CrudController, CrudDefinition, Column, FieldThe same resource classes
compatibility\CrudConfigThe resource class itself
Module Generator (ModulsController, ModuleGenerator, CRUDBooster::generateController())php artisan crudbooster:make-resource Product --generate
A cms_moduls row per modulephp artisan crudbooster:sync-panel adds resources and pages to Privileges > Edit
Statistic Builder (StatisticBuilderController)A page: php artisan crudbooster:make-page (Custom Pages)

Before:

php
class AdminProductsController extends \crocodicstudio\crudbooster\controllers\CBController
{
    public function cbInit()
    {
        $this->table = 'products';
        $this->title_field = 'name';
        $this->orderby = 'name,asc';
        $this->button_export = false;

        $this->col[] = ['label' => 'Name', 'name' => 'name'];
        $this->col[] = ['label' => 'Category', 'name' => 'category_id', 'join' => 'categories,name'];
        $this->col[] = ['label' => 'Price', 'name' => 'price', 'callback_php' => 'number_format($row->price, 2)'];

        $this->form[] = ['label' => 'Name', 'name' => 'name', 'type' => 'text', 'validation' => 'required|max:255'];
        $this->form[] = ['label' => 'Category', 'name' => 'category_id', 'type' => 'select2', 'datatable' => 'categories,name'];
        $this->form[] = ['label' => 'Price', 'name' => 'price', 'type' => 'money'];
    }

    public function hook_before_add(&$postdata)
    {
        $postdata['created_by'] = CRUDBooster::myId();
    }
}

After (app/Admin/Resources/ProductResource.php):

php
use App\Models\Product;
use crocodicstudio\crudbooster\contracts\Security\AuthenticationServiceInterface;
use CrudBooster\Forms\Fields\Select;
use CrudBooster\Forms\Fields\TextInput;
use CrudBooster\Forms\Form;
use CrudBooster\Resources\Resource;
use CrudBooster\Tables\Columns\TextColumn;
use CrudBooster\Tables\Table;

class ProductResource extends Resource
{
    protected static string $model = Product::class;

    protected static ?string $recordTitleAttribute = 'name';

    public function __construct(private AuthenticationServiceInterface $auth)
    {
    }

    public function table(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('name')->searchable()->sortable(),
                TextColumn::make('category.name')->label('Category'),
                TextColumn::make('price')->numeric(2),
            ])
            ->defaultSort('name');
    }

    public function form(Form $form): Form
    {
        return $form->schema([
            TextInput::make('name')->required()->maxLength(255),
            Select::make('category_id')->relationship('category', 'name'),
            TextInput::make('price')->numeric()->prefix('$'),
        ]);
    }

    public function beforeCreate(array $data): array
    {
        return $data + ['created_by' => $this->auth->currentUserId()];
    }
}

The resource needs an Eloquent model with the category() relationship. Give it a new slug (or delete the old module first), since two screens cannot share one URL.

Module properties ​

CBController propertyResource
$table, $primary_key$model (the model's table and key)
$title_field$recordTitleAttribute
$orderby$table->defaultSort('name', 'asc')
$limit$table->paginate(25, [25, 50, 100])
$col$table->columns([...])
$form$form->schema([...])
$button_add, $button_edit, $button_detailLeave create, edit or view out of $pages
$button_delete, $button_table_action$table->withoutDefaultActions(), or a policy
$button_bulk_action$table->withoutBulkDelete()
$addaction$table->actions([Action::make(...)])
$button_selected + actionButtonSelected()$table->bulkActions([BulkAction::make(...)])
$button_filter$table->filters([...])
$button_exportA BulkAction that returns Excel::download(...) or Pdf::loadView(...)->download()
$button_importA page with submit() and a Laravel Excel import
$sub_module, $parent_fieldA second resource with a SelectFilter::relationship(), linked with Column::url()
$table_row_color, $index_statistic, $alert, $pre_index_html, $post_index_htmlPanel::renderHook('index.before', ...) / 'index.after'
$load_js, $load_css, $script_js, $style_cssPanel::renderHook('head', ...) / 'body.end'
$global_privilegeA model policy, or bind your own CrudBooster\Auth\Authorizer
$hide_formField::onlyOn('create'), visible(), hidden()

Hooks ​

CBController hookResource
hook_query_index(&$query)modifyQuery(Builder $query) (every page) or $table->modifyQueryUsing() (the list only)
hook_row_index($index, &$value)Column::formatStateUsing(fn ($state, $record) => ...) or Column::state()
hook_before_add(&$postdata)beforeCreate(array $data): array
hook_after_add($id)afterCreate(Model $record)
hook_before_edit(&$postdata, $id)beforeUpdate(array $data, Model $record): array
hook_after_edit($id)afterUpdate(Model $record)
hook_before_delete($id)beforeDelete(Model $record)
hook_after_delete($id)afterDelete(Model $record)

Model observers and events run too, since resources save with Eloquent.

Columns ​

The $this->col[] entries of cbInit().

Column optionResource column
['label' => 'Name', 'name' => 'name']TextColumn::make('name')->label('Name')
'join' => 'categories,name'TextColumn::make('category.name') (a relationship, eager loaded)
'callback_php', 'callback'formatStateUsing(fn ($state, $record) => ...)
'image' => trueImageColumn::make('photo')
'download' => trueTextColumn::make('file')->url(fn ($record) => asset($record->file), openInNewTab: true)
'str_limit' => 50limit(50)
'nl2br' => trueformatStateUsing(fn ($state) => new HtmlString(nl2br(e($state))))
'visible' => falsehidden()
A subquery columnstate(fn ($record) => ...), or withCount() / withSum() in modifyQuery()

Form types ​

The type of each $this->form[] entry.

typeResource field
textTextInput
email, number, passwordTextInput::make()->email(), ->numeric(), ->password()
moneyTextInput::make()->numeric()->prefix('$')
textareaTextarea
wysiwygViewField with your editor's view
select, select2 with dataenumSelect::make()->options([...])
select, select2, datamodal with datatableSelect::make('category_id')->relationship('category', 'name')
select2 with relationship_tableSelect::make('tags')->relationship('tags', 'name')->multiple()
radioRadio
checkboxCheckboxList (with relationship() for a pivot table)
date, datetime, timeDatePicker, DatePicker::make()->withTime(), ->timeOnly()
upload, filemanagerFileUpload (->image() for images)
hiddenHidden
headerSection::make('Title')->schema([...])
googlemaps, customViewField::make()->view('admin.fields.map'), or your own Field subclass
childA separate resource for the child model
'validation' => 'required|min:3'required(), rules('min:3')
'width' => 'col-sm-6'columnSpan(6)
'help', 'placeholder', 'readonly', 'disabled'helperText(), placeholder(), disabled()

Extension points of classic modules ​

These only serve CBController modules and are deprecated with them.

DeprecatedReplacement
actions\* and CrudActionInterfaceCrudBooster\Actions\Action and BulkAction
FieldHandlerRegistry, FieldHandlerInterface, forms\handlers\*Extend CrudBooster\Forms\Fields\Field (Extending The Panel)
FormProcessor, FormValidator, FormContext and their contractsFields add their own rules and save themselves (dehydrateStateUsing())
GridQueryBuilder, GridFilterParser, GridQuery, GridRowRenderer and their contractsmodifyQuery(), CrudBooster\Tables\Filters\*, your own Column subclass
ExporterRegistry, ExporterInterface, ExcelExporter, CsvExporter, PdfExporter, DefaultExportXls, DefaultImportRowsA BulkAction that returns a download; your own Laravel Excel export and import classes

API Generator ​

DeprecatedReplacement
ApiController, hook_before(), hook_after(), hook_query()A Laravel controller with a form request and a JsonResource
ApiCustomController, ApiGenerator, CRUDBooster::generateAPI()Routes in routes/api.php
CRUDBooster::authAPI()Sanctum, or the CBAuthAPI middleware on your routes

Existing generated APIs keep working, and so do their tokens.

The CRUDBooster helper ​

CRUDBooster::* and its CB alias. Most methods already delegate to a service. Inject the service (constructor, method or closure injection), or call app(Interface::class). Contracts live in crocodicstudio\crudbooster\contracts.

Current admin ​

DeprecatedReplacement
myId()app(Security\AuthenticationServiceInterface::class)->currentUserId()
isSuperadmin()app(Security\AuthenticationServiceInterface::class)->isSuperadmin()
me()CmsUser::find($auth->currentUserId()) (a model rather than a plain row)
myName(), myPhoto(), myPrivilegeId()->name, ->photo, ->id_cms_privileges on that model
myPrivilegeName()->privilege->name on that model
isLocked()session('admin_lock')

Permissions ​

DeprecatedReplacement
isView()$resource->can('viewAny')
isRead()$resource->can('view', $record)
isCreate()$resource->can('create')
isUpdate()$resource->can('update', $record)
isDelete()$resource->can('delete', $record)
isCRUD(), myPrivilege()Check each ability with $resource->can()

Outside a resource, ask app(\CrudBooster\Auth\Authorizer::class)->allows($ability, $slug, $model). A model policy, when there is one, decides first.

URLs, routes and the current module ​

DeprecatedReplacement
mainpath()ProductResource::url() or route('cb.resources.products.index')
adminPath($path)url(config('crudbooster.ADMIN_PATH').'/'.$path), or Resource::url() / Page::url()
getModulePath(), getCurrentModule()static::getSlug() and static::getLabel() inside a resource or page
getCurrentId()The $record the hook or action receives
getCurrentMethod()request()->route()->getActionMethod()
getCurrentMenuId(), getCurrentDashboardId()NavigationItem::activeWhen(); dashboards as pages
sidebarMenu(), sidebarDashboard()app(Navigation\MenuRepositoryInterface::class)->sidebar() / ->dashboard(); add links with Panel::navigationItems()
routeController()Route::get(), Route::post() or Route::resource(); resources and pages register their own routes
isExistsController()app(\CrudBooster\Panel\Panel::class)->getResource($slug)
redirect($to, $msg, $type)return redirect($to)->with(['message' => $msg, 'message_type' => $type]);
redirectBack($msg, $type)return back()->with(['message' => $msg, 'message_type' => $type]);
referer()url()->previous()
getUrlParameters()Resource filters, search and sort are query strings: Resource::url(parameters: [...])
urlFilterColumn(), getValueFilter(), getSortingFilter(), getTypeFilter()CrudBooster\Tables\Filters\*, request('filters.name'), request('sort')
deleteConfirm()Action::make(...)->requiresConfirmation()

Data and schema ​

DeprecatedReplacement
first($table, $id), get($table, ...), insert($table, $data)Eloquent (Product::find(), Product::where()->get(), Product::create()), or DB::table()
newId($table)Let the database assign ids (auto-increment, or HasUuids / HasUlids)
pk(), findPrimaryKey()(new Product)->getKeyName(), or app(Schema\SchemaInspectorInterface::class)->primaryKey($table)
isColumnExists(), isColumnNULL(), getFieldType(), getTableColumns()SchemaInspectorInterface: hasColumn(), isNullable(), columnType(), columns()
listTables()Schema::getTableListing()
parseSqlTable()DB::connection($name)->table($table)
getForeignKey(), getTableForeignKey(), isForeignKey()Relationships on the model (belongsTo(), hasMany())
getNameTable()$recordTitleAttribute
echoSelect2Mult(), CB::ES2M()A relationship column: TextColumn::make('tags.name')

Settings, files, mail, notifications, log, cache ​

DeprecatedReplacement
getSetting($name)app(Settings\SettingsRepositoryInterface::class)->get($name)
uploadFile(), uploadBase64()app(Files\FileUploaderInterface::class)->upload() / ->uploadBase64(), or a FileUpload field
sendEmail(), sendEmailQueue(), mailer()app(Mail\TemplateMailerInterface::class)->send(), ->sendQueued(), ->mailer(), or a Laravel Mailable
sendNotification($config)app(Notifications\NotificationSenderInterface::class)->send($content, $url, $userIds)
sendFCM($tokens, $data)FCM::send((array) $tokens, $data)
insertLog()app(Audit\AuditLoggerInterface::class)->log(); resources log create, update and delete themselves
valid($rules)$request->validate($rules), or rules() on resource fields
putCache(), getCache(), forgetCache(), clearCache(), flushCache()The Cache facade
stringBetween()Str::between()
timeAgo()Carbon::parse($date)->diffForHumans()
packagePath()Internal; no replacement

The Image alias ​

Use Intervention Image v3 directly: \Intervention\Image\ImageManager::gd()->read($path), or the intervention/image-laravel facade. In resources, ImageColumn and FileUpload::image() cover the common cases.

Global functions ​

The functions in src/helpers/Helper.php.

DeprecatedReplacement
cbLang($key, $replace)__('crudbooster::crudbooster.'.$key, $replace)
get_setting($key, $default)app(SettingsRepositoryInterface::class)->get($key) ?: $default
g($key, $default)request($key, $default)
db($table)DB::table($table)
str_random(), str_slug(), str_limit(), ends_with()Str::random(), Str::slug(), Str::limit(), Str::endsWith()
extract_unit()Str::between()
now()Laravel's now() (always defined on Laravel 12+, so this fallback never loads)
assetThumbnail(), assetResize()ImageColumn, or Intervention Image v3 cover()
min_var_export()var_export($value, true)
rrmdir()File::deleteDirectory()

Finding the calls in your app ​

Static analysis lists every deprecated call. With PHPStan and phpstan-deprecation-rules:

bash
composer require --dev phpstan/phpstan phpstan/phpstan-deprecation-rules phpstan/extension-installer
bash
vendor/bin/phpstan analyse app --level=0

Or search for the most common ones:

bash
grep -rnE "CBController|CRUDBooster::|CB::|cbLang\(|get_setting\(" app resources/views

Released under the MIT License.