Inside the $get_user and $get_code , they have group_id.
I have dd (); they both made 100% sure.
a $get_user request has several group_id, and $get_code has only one group_id , which is equal to one of $get_user group_id.
Currently, the goal is to create a group_id matching request.
Get code with group id equal to one of $get_user group_id
public function getCodesViewQr($code_id) { $userid = Auth::id(); $get_user = GroupUser::all()->where('user_id',$userid); $get_code = Code::all()->where('id',$code_id); $group_match = GroupUser::where('group_id', $get_code->group_id); $view['get_users'] = $get_user; $view['get_codes'] = $get_code; $view['group_matchs'] = $group_match; return view('codes.view_qr_code', $view); }
The group match request does not work. $get_code->group_id does not receive group_id code.
If there is a match, set $match to rue. else $match - False
$group_match = GroupUser::where('group_id', $get_code->group_id);
I use two Models Code and GroupUser
My Code table looks like this:
-id
-group_id (This is the only on important right now)
-code_type
My GroupUser table is as follows:
-id
-group_id (This is the only on important right now)
-user_id
-user_role
I knitted Models
In my code model, I have a relationship with GroupUser
public function group_user() { return $this->belongsto('App\GroupUser'); }
And inside my GroupUser model, I have a relationship with Code
public function code() { return $this->belongsto('App\Code'); }
Inside my code controller, I have included my models.
use App\Code; use App\GroupUser;