简体   繁体   English

带有json的laravel中雄辩的关系

[英]eloquent relation in laravel with json

suppose i have two tables(Team and User) in my database . 假设我的数据库中有两个表(Team和User)。 in Team table i have data like "["5","6","7","9","10","26","27"]"(json) , and in users table i have id column in which data is like serial no(Auto_increment .1,2,3 ....nth).is it possible a relation which finds a if json has that single key in it. 在团队表中,我有诸如“ [”“,” 6“,” 7“,” 9“,” 10“,” 26“,” 27“]”(json)之类的数据,而在用户表中,我具有id列其中数据类似于序列号(Auto_increment .1,2,3 .... nth)。是否有可能找到一个json是否具有单个键的关系。 i have a loop statement which has the result that i want but i want that data in relation the code is : 我有一个循环语句,其结果是我想要的,但是我想要与代码相关的数据是:

foreach($model as $key => $value){
        $user_data = User::whereIn('id',json_decode($value->member_ids))->get();
        $model[] = $user_data;
      }

Try this 尝试这个

$arr = json_decode("["5","6","7","9","10","26","27"]");
if (in_array(5, $arr )) {
    // code 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM