Php 如何根据id获取类别名称?
我需要正确分配一些类别和主题的名称。如何根据id获取名称 我有Php 如何根据id获取类别名称?,php,database,laravel,Php,Database,Laravel,我需要正确分配一些类别和主题的名称。如何根据id获取名称 我有career\u solutions表,表中有topic\u category\u id(这是career solutions的category id)。我需要从表categories中的id/category列中获取类别名称 现在,我只从career\u solutions和{{{$user->topic\u category\u id} 这是我的控制器: $user = CareerSolution::where ( 'subj
career\u solutions
表,表中有topic\u category\u id
(这是career solutions的category id)。我需要从表categories
中的id
/category
列中获取类别名称
现在,我只从career\u solutions
和{{{$user->topic\u category\u id}
这是我的控制器:
$user = CareerSolution::where ( 'subject', 'LIKE', '%' . $q . '%' )
->join('role_users' , 'role_users.user_id', '=', 'career_solutions.user_id')
->join('roles' , 'roles.id', '=', 'role_users.role_id')
->join('users', 'users.id', '=', 'career_solutions.user_id')
->orWhere ( 'career_solutions.user_id', 'LIKE', '%' . $q . '%' )
->orWhere ( 'career_solutions.id', '=', 'events.subject')
->orWhere('career_solutions.topic_category_id' ,'=', $category->id)
->orWhere ( 'career_solutions.user_id', '=', 'users.username')
->select('career_solutions.id as id','subject','users.id as user_id','username', 'profile_picture', 'role_id', 'optional', 'topic_category_id')
->get ();
也连接category表并从该表中获取categoryname
$user = CareerSolution::where ( 'subject', 'LIKE', '%' . $q . '%' )
->join('role_users' , 'role_users.user_id', '=', 'career_solutions.user_id')
->join('roles' , 'roles.id', '=', 'role_users.role_id')
->join('users', 'users.id', '=', 'career_solutions.user_id')
->join('categories', 'categories.id', '=', 'career_solutions.topic_category_id')
->orWhere ( 'career_solutions.user_id', 'LIKE', '%' . $q . '%' )
->orWhere ( 'career_solutions.id', '=', 'events.subject')
->orWhere('career_solutions.topic_category_id' ,'=', $category->id)
->orWhere ( 'career_solutions.user_id', '=', 'users.username')
->select('career_solutions.id as id','subject','users.id as user_id','username', 'profile_picture', 'role_id', 'optional', 'topic_category_id','categories.name')
->get ();
并调用{{$user->name}