Laravel eloquent where error with <>

前端 未结 3 2036
粉色の甜心
粉色の甜心 2021-02-20 03:22

I have query for where in native php

where type <> \'point\'

and I try convert to eloquent laravel<

相关标签:
3条回答
  • 2021-02-20 03:26

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

    ->with(['payments' => function ($query) {
        $query->where('type', '<>', 'point');
    }])
    
    0 讨论(0)
  • 2021-02-20 03:41

    to parse the dynamic parameters within query try this :

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

    this will work!!

    0 讨论(0)
  • 2021-02-20 03:51

    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.

    0 讨论(0)
提交回复
热议问题