2017-11-10 92 views
0

如何檢查表中但同一行中的兩個變量是否存在然後執行 示例 我有客戶表具有id(autoincreament),customer_id,package id等只想檢查CUSTOMER_ID和的package_id等於請求然後做 我試過,但不起作用laravel檢查同一行中的兩個變量是否有效

public function redirectpackage(Request $request) 
{ 
if(Customer::where('customer_id', 'LIKE', $request->customer_id) && 
(Customer::where('package_id', 'LIKE', $request->package_id))->exists()) { 

    return view('index.customer.customerabout'); 
} else 
{ 
return redirect()->intended(route('home')); 
} 
} 

回答

-1

您需要遍歷你的客戶所要檢查的客戶編號和包裝標識的要求。

例如:

public function redirectpackage(Request $request) 
{ 

$customers = Customer::all(); 

foreach ($customers as $customer) { 

    if($customer->id', $request->customer_id) and 
($customer->packages->id', $request->package_id) { 

     return view('index.customer.customerabout'); 
    } else 
    { 
     return redirect()->intended(route('home')); 
    } 
} 

這應該讓你開始。您需要修改以適應您的模型和關係。

0
public function redirectpackage(Request $request) 
{ 
if(Customer::where('customer_id','=',(Auth::user()->id))->where('package_id','>',0)->first()) 

{ 
return view('index.customer.customerabout'); 

} 
else 
{ 
return redirect()->intended(route('home')); 
} 
} 

    } 
0
public function redirectpackage(Request $request){ 

    if(Customer::where('customer_id', 'LIKE', $request->customer_id)->where('package_id', 'LIKE', $request->package_id))->first()) { 
     return view('index.customer.customerabout'); 
    } else { 
     return redirect()->intended(route('home')); 
    } 
} 
相關問題