itrabbi24
6 days ago

Laravel Qurey Dynamic Variable Problem

Posted 6 days ago by itrabbi24

I get some value from my database.

$auth_dept_code = Auth::user()->dept_code; // 1 $auth_branch_code = Auth::user()->branch_code; //0001 $auth_code = $auth_dept_code.$auth_branch_code ; // 1001

//auth_code is 1001

Now

when I am search

tmsid LIKE '%$auth_code%'

LIKE '%{$auth_code}%'

LIKE '%?%' )", [$auth_code]

this variable auth_code that is not working...... but when I am declared variable is

$auth_code = 1001;

and Query is executed at that time is working... but I need a dynamic variable to search.

why dynamic variables are not working?? Please give me a solution.

please give me a solution.

Here is some screenshot

Not Working

https://imgur.com/a/GRyZHfm

Working type of static value

https://imgur.com/a/iIcV8al

Not Working...

https://imgur.com/a/AhA4GXU

OR

https://imgur.com/a/8g79AYp

same problem

the dynamic variable is not working

$auth_dept_code = Auth::user()->dept_code; 		// 1
$auth_branch_code = Auth::user()->branch_code;	// 0001
$auth_code = intval($auth_dept_code.$auth_branch_code); //1001 




error_reporting( ~E_NOTICE );

$submenus =DB::select(DB::raw("SELECT tmsid, RIGHT(tmsid,6) 
	as max_number FROM tms_tables WHERE tmsid=(SELECT MAX(tmsid) 
	FROM tms_tables where tmsid LIKE '%auth_code%' )"));

@endphp

@foreach($submenus as $row)
@endforeach
@php
  $num = $row->max_number;
    ++$num;
      $len = strlen($num);
          for($i=$len; $i< 6; ++$i) {
        $num = '0'.$num;
      }
@endphp


@php
echo $auth_code; echo '-'; echo $num;
@endphp

Please sign in or create an account to participate in this conversation.