You can use a collection to ensure data security without having to check for something before you call it. For example:
$name = 'Rafael Henrique Berro';
$arr = explode(' ', $name);
$collection = collect($arr);
$firstname = $collection->shift();
$lastname = $collection->shift();
// outputs: Rafael Henrique
You can also choose to use other methods of the collection itself, for example:
$name = 'Rafael Henrique Berro';
$arr = explode(' ', $name);
$names = collect($arr)->slice(0, 2)->implode(' ');
// outputs: Rafael Henrique
In one line, it's confusing but it works:
$names = collect(explode(' ', Auth::user()->name))->slice(0, 2)->implode(' ');
It pays to check available methods and what a collection is in the official documentation .