vendredi 14 mai 2021

get the null value from the table

I have 3 tables meeting ,user and user_role.I want to get the value if the also null if I choose blank. $_REQUEST['created_by_user_role'] is Array ( [0] => AM [1] => IS [2] => Mktg [3] => sales user [4] => Blank ) when blank in array I want to get the meeting id 1,2,3

Example table data

meeting
 id created_by_name 
 1   a
 3
 2   b

user
 id user_name user_role
  1  a         1
  2  b         2

user_role
id user_role
 1    role_1
 2    role_2 

Code

<?php
$meeting_details = DB::table('meeting')
    ->leftJoin('users as users_created', 'meeting.created_by_name', '=', 'users_created.user_name')
    ->leftJoin('user_roles as role_created', 'users_created.user_role', '=', 'role_created.id');

if (count($_REQUEST['created_by_user_role'])) {
    $filter_created_by_user_role = DB::table('user_roles')
        ->whereIn('roles', $created_by_user_role)
        ->pluck('id')
        ->toArray();
}

$meeting_details = $meeting_details->whereIn('users_created.user_role', $filter_created_by_user_role);

if (in_array('Blank', $request['created_by_user_role'])) {
    $filter_created_by_user_role[] = null;
    $meeting_details = $meeting_details->whereNull('users_created.user_role');
}

$meeting_details = $meeting_details->select('id')->get();

my above query returns



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire