Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 461
Muhamad Yulianto Avatar asked Jan 03 '17 04:01

Muhamad Yulianto


3 Answers

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

->with(['payments' => function ($query) {
    $query->where('type', '<>', 'point');
}])
like image 52
Alexey Mezenin Avatar answered Oct 22 '22 02:10

Alexey Mezenin


to parse the dynamic parameters within query try this :

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

this will work!!

like image 41
Manish J Avatar answered Oct 22 '22 02:10

Manish J


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.

like image 1
Mike Harrison Avatar answered Oct 22 '22 02:10

Mike Harrison