useUccello\Core\Models\Module;$module =ucmodule(1);echo $module->name;// => userechoucmodule('user')->name;// => userechoModule::where('name','user')->first()->name;// => user
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
$personModule =ucmodule('person');echouctrans('field.first_name', $personModule);// => First name (from resources/lang/en/person.php)$userModule =ucmodule('user');echouctrans('block.general', $userModule); // This label is not translated in user module// => General information (from vendor/uccello/uccello/resources/lang/en/default.php)echotrans('uccello::default.block.general');// => General information
ucroute()
Retrieves a route and automatically adds domain and module params.
The domain param is only added if the multi domains option is enabled.
$domain =ucdomain('uccello');$module =ucmodule('user');echoucroute('uccello.list', $domain, $module);// => /uccello/user/list (with multi domains enabled)// => /user/list (with multi domains disabled)echoroute('uccello.list', ['domain'=> $domain->slug,'module'=> $module->name]);// => /uccello/user/list (with multi domains enabled)// => /user/list?domain=uccello (with multi domains disabled)echoucroute('uccello.detail', $domain, $module, ['id'=>1];// => /uccello/user/detail?id=1 (with multi domains enabled)// => /user/detail?id=1 (with multi domains disabled)
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.
$user =auth()->user();// The ACME domain is a child of Uccello domain.$acmeUser =\App\User::where('domain_id',ucdomain('acme'))->first();echoucattribute($user,'domain.name');// => Uccelloechoucattribute($user,'domain.parent.name');// => nullechoucattribute($acmeUser,'domain.parent.name');// => Uccello
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.
ucnotify('My message'); // Displays a black info toastucnotify('Info message','info'); // Displays a black info toastucnotify('Success message','success'); // Displays a green success toastucnotify('Warning message','warning'); // Displays an orange warning toastucnotify('Error message','error'); // Displays a red error toast
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.
// Retrieve by uuid$record =ucrecord('00013d27-1195-4bcc-b05d-ee63e2aaa471');// Retrieve by id and model class$record =ucrecord(1,\App\User::class);