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


0 votes
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 }}

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