문제

I've got a Laravel model, but i'd like to search the table according to an array passed in.

i.e. "Return all rows whose id matches one of the array's contents"

I can see with Laravel's query builder i can search via an input array:

$users = DB::table('teams')->whereIn('id', array(1, 2, 3))->get();

But can't seem to find anywhere how to do the same using a model.

Any ideas? Cheers!

도움이 되었습니까?

해결책

Replace DB::table('teams')-> with a static call to the model.

$users = <model name>::whereIn('id', array(1, 2, 3))->get();

다른 팁

You can try this.

<?php
use App\Models\Team;

$users = Team::whereIn('id', array(1, 2, 3))->get();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top