口才如何在多个“ where”中使用“ or”?

时间:2018-09-03 16:47:21

标签: php mysql laravel eloquent

我该如何在Eloquent中实现呢?

select * from product where name like '%value%' and (product_type = product_type_param or product_type_param = 0);

如果提供了product_type_param的{​​{1}}值,那么它将选择所有类型的产品,当然还要考虑到名称也匹配。

我当前的代码:

0

这个想法将是这样的(请以示例为例,它仅显示了我的意图):

$result = Product::where( [  ['name', 'like', '%' . 
$searchAttributes['name'] . '%'],
    ['product_type', '=', $searchAttributes['product_type']]]
     )->get();

我应该执行原始查询吗?

2 个答案:

答案 0 :(得分:1)

您可以使用闭包函数来限定查询范围

Comparator

答案 1 :(得分:0)

使用<ion-slides #signupSlider> <ion-slide> <ion-list> <form novalidate [formGroup]="slideOneForm"> <ion-item> <ion-label color="white" fixed>First Name:</ion-label> <ion-input type="text" placeholder="Enter your First Name" formControlName="fname" [(ngModel)]="userData.fname" [ngModelOptions]="{standalone: true}"></ion-input> </ion-item> </form> </ion-list> </ion-slide> <ion-slide> <ion-list> <form novalidate (ngSubmit)="signup()" [formGroup]="slideTwoForm"> <ion-item> <ion-label color="white" fixed>Address:</ion-label> <ion-textarea placeholder="Enter your Address" rows="3" formControlName="address" [(ngModel)]="userData.address"></ion-textarea> </ion-item> </form> </ion-list> <button ion-button round (click)="signup()" [disabled]="slideTwoForm.invalid">Signup</button> </ion-slide> </ion-slides>

import { Component,OnInit,ViewChild } from '@angular/core';
import { ToastController,LoadingController  } from 'ionic-angular';
import { FormControl, FormGroup, Validators, AbstractControl, ValidatorFn } 
from '@angular/forms';

import { AuthServiceProvider } from '../../providers/auth-service/auth- 
service';
import { LoginPage } from '../login/login';

@Component({
 selector: 'page-signup',
 templateUrl: 'signup.html',
})
export class SignupPage {
 responseData : any;
 slideOneForm: FormGroup;
 slideTwoForm: FormGroup;
 userData = { "fname": "", "address": "" };

@ViewChild('signupSlider') signupSlider: any;

constructor(
 private authService: AuthServiceProvider, 
 public toastCtrl: ToastController,
 public loadingCtrl: LoadingController) {
}

ionViewDidLoad() {
  this.signupSlider.lockSwipes(true);
}
ngOnInit(){
this.slideOneForm = new FormGroup({
  fname: new FormControl('', [Validators.maxLength(30), Validators.pattern('[a-zA-Z ]*'), Validators.required]),
});
this.slideTwoForm = new FormGroup({
  address: new FormControl('', [Validators.pattern('[a-zA-Z ]*'), Validators.required]),
});
}

}