Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k views
in Technique[技术] by (71.8m points)

eloquent - Laravel - use multiple value in where DB query

in my posts table have extra_category column with saved mutiple value(json) same ["12","15","23"] now I want use this value in DB query for get category name for each value .

my Controller:

$excatname = DB::table('categories')
               ->where('id', '=', $post->extra_category)->get();
                   view()->share('excatname', $excatname);

and my view:

    @foreach($excatname as $excatnamez)
      {{ $excatnamez->name }}
    @endforeach

but get error:

SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens (SQL: select * from `categories` where `id` = 12) 

Note: when extra_categoy have single value for ex : 15 worked as well. cast is defined on the model protected $casts = ['extra_category' => 'array',]


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...