A helper is a php function you can use in all your application, in both controllers and views.
Default helpers
ucdomain()
Retrieves a domain by id or slug.
use Uccello\Core\Models\Domain;$domain =ucdomain(1);echo$domain->name;// => Uccelloechoucdomain('uccello')->name;// => Uccelloecho Domain::where('slug','uccello')->first()->name;// => Uccello
ucmodule()
Retrieves a module by id or name.
As Uccello cache the modules, please don't use ucmodule($moduleName) in your migration files. Your new created module could be not accessible with this helper.
Use Module::where('name', $moduleName)->first() instead.
uctrans()
Retrieves the complete prefix of a label and translated it.
If the translation does not exist, it tries to find a default one according to priorities.
If no translation exist, it displays only the label without translation.
Priority:
Translation overridden in app
Translation in package
Default translation overridden in app
Default translation in uccello
No translation
ucroute()
Retrieves a route and automatically adds domain and module params.
The domain param is only added if the multi domains option is enabled.
Returns the complete path of an asset available in an external package.
ucattribute()
Returns a record attribute value. It is able to follow a complex path according to models definition (e.g. 'domain.parent.name'). If the attribute is not accessible, it returns null.
To be able to use this helper, you have to define the belongsTo relations in the different models.
ucnotify()
Displays a flash info toast containing the message of your choice.
ucrecord()
Retrieves a record by id or uuid. If you want to retrieves a record by its id, you have to specify its model class two.
All records have an uuid defined in the database table called by default uccello_entities.
use Uccello\Core\Models\Module;
$module = ucmodule(1);
echo $module->name;
// => user
echo ucmodule('user')->name;
// => user
echo Module::where('name', 'user')->first()->name;
// => user
$personModule = ucmodule('person');
echo uctrans('field.first_name', $personModule);
// => First name (from resources/lang/en/person.php)
$userModule = ucmodule('user');
echo uctrans('block.general', $userModule); // This label is not translated in user module
// => General information (from vendor/uccello/uccello/resources/lang/en/default.php)
echo trans('uccello::default.block.general');
// => General information
use Uccello\Core\Models\Uitype;
echo uitype(1)->name;
// => text
echo uitype('text')->name;
// => text
echo Uitype::where('name', 'text')->name;
// => text
$user = auth()->user();
// The ACME domain is a child of Uccello domain.
$acmeUser = \App\User::where('domain_id', ucdomain('acme'))->first();
echo ucattribute($user, 'domain.name');
// => Uccello
echo ucattribute($user, 'domain.parent.name');
// => null
echo ucattribute($acmeUser, 'domain.parent.name');
// => Uccello
ucnotify('My message'); // Displays a black info toast
ucnotify('Info message', 'info'); // Displays a black info toast
ucnotify('Success message', 'success'); // Displays a green success toast
ucnotify('Warning message', 'warning'); // Displays an orange warning toast
ucnotify('Error message', 'error'); // Displays a red error toast
// Retrieve by uuid
$record = ucrecord('00013d27-1195-4bcc-b05d-ee63e2aaa471');
// Retrieve by id and model class
$record = ucrecord(1, \App\User::class);