2017-03-16 72 views
1

我是laravel的新手,我一直在學習更多的東西。但是現在我得到了一個我在普通PHP中從未見過的錯誤。我在函數目錄中測試的某些運算符不起作用,而其他運算符則是這樣。只有=,!=和<>工作,而<,>,> =和< =沒有。運營商似乎沒有在Laravel工作

它給了我:「非法運營商和價值組合」;還有:->where('Price', '(operator)', **null**)。我曾嘗試過「wherenull」但不起作用。任何人都可以幫我解決這個問題嗎?我正在使用laravel 5.4。

的代碼:

控制器(在這種情況下我已經把 「> =」 它不工作)

function catalog(Request $abc) { 
    $categoryesc = $abc->categoryesc; 
    $priceesc = $abc->priceesc; 
    $categories = DB::table('categories')->pluck('Category', 'id'); 
    $robots = DB::table('robots')->where('Category_id', $categoryesc)->where('Price', '>=', $priceesc)->get(); 
    return view('catalog', compact('robots', 'categories')); 
} 

視圖

@extends('layouts.layout') 
@include('header') 

<main> 
<div>Choose the category</div> 
{!! Form::open(array('method' => 'GET')) !!} 
    {!! Form::select('categoryesc', $categories) !!} 
    {{ Form::number('priceesc') }} 
    {!! Form::submit('Ok') !!} 
{!! Form::close() !!} 

<div>Choose the model</div> 
<b>On this page ({{ $robots->count() }} robots)</b> 

<div id="area1"> 
@foreach($robots as $robot) 
    {!! Form::open(array('action' => '[email protected]', 'method' => 'GET')) !!} 
    {!! Form::hidden('modelesc', $robot->Model) !!} 
    {!! Form::submit($robot->Model) !!} 
    {!! Form::close() !!} 
@endforeach 
</div> 

</main> 

完整的錯誤信息是:

Builder.php中的InvalidArgumentException l INE 609:非法運算符和值組合

表觀解

我認爲我已經解決了這個:我去到該文件在\vendor\laravel\framework\src\illuminate\database\query\builder.php和線627增加了「< =」(下我想要使​​用的運算符)。現在它正在工作。否則我會在稍後回到這個。

+1

可以提供錯誤的全文? – jackel414

+1

請檢查您的數據類型?什麼類型是價格? – Boris

+0

@ jacket414 - 完整的錯誤消息是:Builder.php中的InvalidArgumentException行609: 非法操作符和值組合。 – Adato

回答

0

此時,您應該開始對$robots查詢的輸入進行故障排除。

而不是返回視圖返回$robots之前所有查詢返回的值。如果有任何不正確,開始檢查爲什麼(也許它不具有任何數據或錯誤的數據)

function catalog(Request $abc) { 
    $categoryesc = $abc->categoryesc; 
    //$priceesc = $abc->priceesc; 
    //$categories = DB::table('categories')->pluck('Category', 'id'); 
    //$robots = DB::table('robots')->where('Category_id', $categoryesc)->where('Price', '>=', $priceesc)->get(); 
    dd($categoryesc); // is this the correct value you want to send to the `$robots` query? If yes continue to next variable 
} 

檢查第二個變量:

function catalog(Request $abc) { 
$categoryesc = $abc->categoryesc; 
$priceesc = $abc->priceesc; 
//$categories = DB::table('categories')->pluck('Category', 'id'); 
//$robots = DB::table('robots')->where('Category_id', $categoryesc)->where('Price', '>=', $priceesc)->get(); 
//return view('catalog', compact('robots', 'categories')); 
dd($priceesc); // is this the correct value you want to send to the `$robots` query? If yes continue to next variable and so on 
} 

他們都不應該返回一個數組。如果其中一個值是數組,則最後的查詢將不起作用。

更新:

你的形式不發送的值到function catalog

+0

我檢查了兩個變量。只有「null」的空白屏幕我怎樣才能解決這個問題? – Adato

+0

正如@Amraly已經說過的,你的請求是空的,你的表單有問題,請讓我檢查表格 – davejal

+0

我沒有看到它應該的url發送值... – davejal