samedi 21 juillet 2018

how to select all instances of a model if a string is in input array

if I got an array like $tags = ['first', 'second', 'etc']

how do I select all instances of model from database where one of the columns only holds one of values found in the array above.

How would my where look? How do I loop through the array and construc the correct query so I do not miss any objects?

Querently I have decided to place it inside a local scope

public function scopeTriptags($query, $triptags) {
    foreach ($triptags as $triptag) {
        $query->where()
    }
}

I am not sure if I can just chain them using where? if I should use orWhere will that work correctly if orWhere is used in the first loop?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire