Retrieve Laravel Model results based on multiple ID's

后端 未结 1 1230
隐瞒了意图╮
隐瞒了意图╮ 2021-01-30 03:43

I have implemented ZendSearch into my Laravel application. I am using it as my search engine where users will type a search word, and then ZendS

相关标签:
1条回答
  • 2021-01-30 04:29

    That's simple. Use findMany:

    $models = Model::findMany([1, 2, 3]);
    

    By the way, you can also pass an array to find() and it will internally call findMany:

    $models = Model::find([1, 2, 3]);
    

    Under the hood it just does a whereIn so you could do that too:

    $models = Model::whereIn('id', [1, 2, 3])->get();
    
    0 讨论(0)
提交回复
热议问题