简体   繁体   中英

Laravel eloquent where error with <>

I have query for where in native php

where type <> 'point'

and I try convert to eloquent laravel

 ->with('payments',function($query){
      $query->where('type','<>','point');
 })

but it is showing error as follows:

mb_strpos() expects parameter 1 to be string, object given

You're using wrong syntax. Correct syntax for with() is:

->with(['payments' => function ($query) {
    $query->where('type', '<>', 'point');
}])

If that is all you need to do with the query then you can just chain it like this:

->with('payments')->where('type', '<>', 'point') //chain more after this

Correct answer should be this if you are trying to filter payments where the type is not equal to point .

to parse the dynamic parameters within query try this :

$string = 'points';
->with(['payments' => function ($query) use ($string) {
    $query->where('type', '<>', $string);
}])

this will work!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM