Last active
August 31, 2016 18:47
-
-
Save julianobailao/307cff33ddd264e96d53ea1e96fff689 to your computer and use it in GitHub Desktop.
Using collection find method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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