使用模型关联查询地址,如何取到地址信息里面的值
这是我的laravel模型代码
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class EduCourse extends Model
{
// 获取分页的课程列表
public static function getListOfPage(){
return self::with('country')->paginate();
}
// 课程表关联国家的id
public function country(){
return $this->belongsTo('App\Models\EduDistrict');
}
}
查询后,这是输出的列表的部分数据
city_id: 2133
country: {id: 1, name: "中国", level: 1, parent_id: 0, showOrder: 0, code: ""}
code: ""
id: 1
level: 1
name: "中国"
parent_id: 0
showOrder: 0
country_id: 1
course_cate_id: 11
发现这里的country是一个json字符串,我想直接取到里面的name字段的中国的值。该怎么办
推荐文章: