Helpers
VEnumHelper
this trait brings useful static methods to enum classes.
Available methods
toArray
Convert values of an enum class to an array.
toArrayKeys
Convert keys of an enum class to an array.
toArrayExcept
Convert values of an enum class to an array except the given values.
toArrayKeysExcept
Convert keys of an enum class to an array except the given keys.
toArrayOnly
Convert given values of an enum class to an array.
toArrayKeysOnly
Convert given keys of an enum class to an array.
all
Create an array using all enum members.
IndexedAll
Create an array using values of all enum members.
tryFromKey
Find a value using the given key, otherwise return the default value.
Functions
Valravn includes several global functions that you can use in your code.
user
Return authenticated user or optional null.
resolveRelatedIdToModel
Resolve the given id to a related model.
resolveMorphableToResource
Resolve given Model to a resource class.
vlog
Log the error in a dedicated channel with a simplified format. First, To create the channel, Add these
lines in config/logging.php
:
1'channels' => [
2 // ...
3 'valravn' => [
4 'driver' => 'daily',
5 'path' => storage_path('logs/valravn.log'),
6 'level' => 'debug',
7 'days' => 1,
8 'replace_placeholders' => true,
9 ]
10],
Then, You can use the vlog
function like below examples.
1class someClass {
2 public function someMethod(): void
3 {
4 try{
5 // do something
6 }catch (Exception $e){
7 vlog('The reason');
8 }
9 }
10}
The logged content should be like this:
1[2025-01-06 07:57:54] testing.DEBUG: At: [Namespace\someClass::someMethod] => "The reason"
Also, You can pass the exception to track the issue.
1catch (Exception $e){
2 vlog('The reason',['previous' => $e]);
3}
And if you just want to log the error, you need to pass the exception only.
1catch (Exception $e){
2 vlog($e);
3}
slugify
Make a english or non-english string to a slug.