1. Logger
The logger helper function can be used to write a message with a debug level to the log.
to check the log message go to storage/log and the message should be look like the following#0 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(2, 'file_put_conten...', '/var/www/Blog...', 122, Array)
2. Dividing an array
The Arr::divide()
method lets you split up an array in two arrays. The divide method returns two arrays. One array containing the keys and the other array containing the values.
use Illuminate\Support\Arr;
[$keys, $values] = Arr::divide(['name' => 'James', 'age' => 33]);
$keys: ['name', 'age']
$values: ['James', 33]
3. Blank
The blank
helper function checks whether a value is “blank”. A “blank” value means null, a string only containing whitespaces or an empty array or string.
Note:
Booleans are not considered “blank” values.
blank('');
blank(' ');
blank(null);
blank(collect());
// Will result in: true
blank(0);
blank(true);
blank(false);
// Will result in: false
The inverse of this helper function is the filled helper function.
4. Dumping variables
Dumping variables is very handy if you want to debug one or more variables.
dump($variable);
5. Array has value
The Arr:has
method can be used to check whether an item or multiple items exist in an array using the “dot” notation.
To check for multiple items simply pass an array instead of a string to the method.
use Illuminate\Support\Arr;
$blogs = ['blog' => ['title' => 'My blog', 'published' => true]];
$contains = Arr::has($blogs, 'blog.title');
// true
$contains = Arr::has($blogs, ['blog.title', 'blog.published']);
// true
$contains = Arr::has($blogs, ['blog.title', 'blog.author']);
// false