0

The users is json encoded

$agent_id = $request->get('user');

$model = AgentPermission::select('module_category')->where('users', 'like', '%$agent_id%')->get();

I want to to show "module category" where json encoded data is present in "users" column if it is working the whole code is working fine because when i use this

$model = AgentPermission::select('module_category')->where('users', 'like', '%"10"%')->get();  it is working perfect
Rwd
  • 34,180
  • 6
  • 64
  • 78
Nabeel Ali
  • 19
  • 5

1 Answers1

0

The comparison should be inside double quotes, not single quotes

$model = AgentPermission::select('module_category')->where('users', 'like', "%$agent_id%")->get();

since PHP injects variables only when using double quotes.

The alternative is:

$model = AgentPermission::select('module_category')->where('users', 'like', '%' . $agent_id . '%')->get();
JoeGalind
  • 3,545
  • 2
  • 29
  • 33