Sunday, 15 September 2013

laravel - Eloquent select specific columns -


I am trying to choose specific column using Laravel's alcove but I have some problems. I want to select quantity, I have tried prices by prices

$ value = value :: select (array ('quantity', 'value')) -> Where meaning and year and type ($ month, $ year, 'CPI') - & gt; (Select the array ('product' = & gt; function ($ query) {$ query- & gt; ('id', 'name');})) - & gt; Select {$ query-> ('id', 'name');}) with & gt; (array ('market' = & gt; function $ query) get ();

But I am trying to get the non-object property

There is nothing in your code snippet that will cause that error. However, I suspect that when you are keenly looking forward to reaching the fields when loaded product or market relationships are not checked for your existence, you Getting the error.

A common problem with specifying selected statements and specifying anxious loading relationships is that local and foreign keys generally come out, however, these values ​​are that Laravel will have all related models Use to match, so it is also necessary to be selected.

If the price is for a product and the price is for a market, then you also select the prices. Product_id and prices.MARKAT_ID field If price is a product or price is the same market, then you have to select the respective foreign key on prices.ID field and eagerly loaded relationships (products.price_id or markets.price_id).

However, even once it has been resolved, it is still a good idea to check that the relevant records exist before reaching it. In a haan / related relationship, if the related record is not present, then the relationship property will be tulled if you try to use a field on zero, you will see the error.


No comments:

Post a Comment