skip to Main Content

I have the following query params in string format

$query =  '->whereIn('short_code', ["9999"])->whereBetween('request_timestamp', [request('startTime'), request('endTime')])';

How do i pass it to the eloquent? Am trying to achieve something like this

InboundMessage::query()->{$query};

Am getting the error below

Property [->whereIn('short_code', ["9999"])->whereBetween('request_timestamp', [request('startTime'), request('endTime')])] does not exist on the Eloquent builder instance. 

2

Answers


  1. The problem with the above query is that it looks like this

    InboundMessage::query()->->whereIn('short_code', ["9999"])..
    

    Since you have put -> in both the query builder and the $query string. So just adjust your $query to

    $query = 'whereIn('short_code', ["9999"])->whereBetween('request_timestamp', [request('startTime'), request('endTime')])';
    
    Login or Signup to reply.
  2. It will be something like this (not tested) using raw DB expressions:

    $query = DB::table('tableName')
    ->whereRaw('columnName IN ["9999"] AND columnName BETWEEN value1 AND value2')
    ->get();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search