Skip to content

Instantly share code, notes, and snippets.

@julianobailao
Last active August 31, 2016 18:47
Show Gist options
  • Save julianobailao/307cff33ddd264e96d53ea1e96fff689 to your computer and use it in GitHub Desktop.
Save julianobailao/307cff33ddd264e96d53ea1e96fff689 to your computer and use it in GitHub Desktop.
Using collection find method
<?php
$main_address = $customer->address()->find('main_address')->getFullAddressText();
// Street name, 12345 - City name - My state
// Quando utilizamos o método find para buscar um ítem, ele retornará o objeto presente neste índice,
// ou null caso seja um indíce não existente. A collection possui também o método findOrFail, funciona de
// forma semelhante ao find, porém caso tente buscar um índice não existente, retornará uma exceção do tipo
// CollectionItemNotFoundException
$main_address = $customer->address()->findOrFail('main_address')->getFullAddressText();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment