Wednesday, April 12, 2017

Handling Failed eloquent methods

im calling a products information fields, has you see above:

$product->attributes->first()->attributeValues->where('locale',$iso);

Basiclly in the "$product" variable already have information regarding the product, than i made "$product->attributes->first()" to get his attributes, and after getting his attributes i go get his values "attributeValues->where('locale',$iso)" with the specific language. The data it outputs good, but only if there exist attributes, because case it doesnt because of the "attributeValues" method the page fails. How can i handle in this situation?



via Pedro

Advertisement