简体   繁体   中英

How Can i Search a Value in Database If a Column Contains JSON Encode Data in Laravel

Hello I want to get the vendor_service_area from the following data which is in table basically the data i stored in the details Column With JSON Encoded桌子

Here is my query:

$user_details = DB::table('users_details')->where('user_id',11)->get();

You can define the columns as array in your model. Something like this:

class UserDetail extends Model
{
    .
    .
    .
    protected $casts = [
        'details' => 'array',
    ];
    .
    .
    .
}

And then you can access the vendor_service_area with something like this:

$user_details->details['profile_details']['vendor_service_area'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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