laravel - Filtering Eloquent Collection -


Trying to filter the collection object based on any combination of multiple values, as far as I have found Not happening. Any clue for me?

  Public function search () {$ posts = posting :: All (); $ Type_id = Input :: find ('type_id'); $ Country_id = input :: find ('country_id'); $ Province_id = input :: get ('province_id'); $ Post = $ posts- & gt; Filter (function ($ post) {if (empty! ($ Type_id) & amp; amp; $ type_id> 0) Return to {$ post-> where ('type_id', '=', $ Type_id) ;}}) - & gt; value (); $ Post = $ post- & gt; Filter (function ($ post) {if (empty ($ country_id) & amp; amp; amp; amp; amp; country country & amp; id; $ country_id}}}) & gt; value (); $ Post = $ posts- & gt; Filter (function ($ post) {if (empty! ($ Province_id) & amp; amp; amp; $ province_id> 0) {back to $ post-> where ('province_id', '= ', $ Province_id);}}} - & gt; value (); Return $ post; }  

Any help appreciated.

First of all, should you actually be greater than 0 with the id Verify if they are provided. You should not be checked manually

But by no means, why are you using filters, when you can use the eCalcon directly (I have made the ID check greater than 0):

  $ type_id = input :: find ('type_id'); $ Country_id = input :: find ('country_id'); $ Province_id = input :: get ('province_id'); $ Query = Posting :: Query (); If (empty! ($ Type_id)) $ query- & gt; WhereTypeId ($ type_id); If (! Bottom ($ country_id)) $ query- & gt; The country's ID ($ country_id); If (empty! ($ Province_id)) $ query- & gt; Where admitted ($ province_id); Return $ query- & gt; get receive ();  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -