2017-05-08 102 views
0

嗨,我想知道如何創建一個「選擇」中的「選擇」,獲得所有可能的值,「選擇」。我試過了在哪裏,在哪裏,但是不能得到它。有人甚至提到使用Jquery。 laravel版本是5.4。laravel - 選項所有值

這是代碼:

控制器

function catalog(Request $abc) { 
    $categoryesc = $abc->categoryesc; 
    $manufaesc = $abc->manufaesc; 
    $priceesc = $abc->priceesc; 
    $modelesc = $abc->modelesc; 
    if (empty($modelesc)) { 

     $robots = DB::table('robots')->where('Category_id', [$categoryesc])->where('Manufacturer_id', [$manufaesc])->where('Price', '<=', $priceesc)->get(); 
    }elseif (Auth::check()){ 
     $robots = DB::table('robots')->where('Model', $modelesc)->first(); 
     $colours = DB::table('colours')->pluck('Colour', 'id'); 
    } 
    else { 
     return redirect('login'); 
    } 
    return view('catalog', compact('robots', 'categories', 'colours')); 
} 

刀片文件:

{{ Form::open(array('method' => 'GET')) }} 
    {{ Form::select('categoryesc', ['0' => 'Any Category', '1' => 'Light', '2' => 'Medium', '3' => 'Heavy'], '0') }} 
    {{ Form::select('manufaesc', ['0' => 'Any Make', '1' => 'Xenon', '2' => 'Tauron'], '0') }} 
    {{ Form::select('priceesc', ['0' => 'Any Price', '100' => '100', '200' => '200'], '0') }} 
    {{ Form::submit('Search') }} 
{{ Form::close() }} 

錯誤:

ErrorException in 164eed4705c5997d268ffab821c82effa7651a2b.php line 31: 
Undefined property: Illuminate\Database\MySqlConnection::$Model (View: C: 
(...)\resources\views\catalog.blade.php) 

in 164eed4705c5997d268ffab821c82effa7651a2b.php line 31 

at CompilerEngine->handleViewException(object(ErrorException), 1) in 
PhpEngine.php line 44 

at PhpEngine->evaluatePath('C:\\(...) \\ storage\\ framework\\ views/ 
164eed4705c5997d268ffab821c82effa7651a2b.php', array('__env' => 
object(Factory), 'app' => object(Application), 'errors' => 
object(ViewErrorBag), 'robots' => object(Builder))) in CompilerEngine.php 
line 59 

at CompilerEngine->get('C:(...)\\resources\\views/catalog.blade.php', 
array('__env' => object(Factory), 'app' => object(Application), 'errors' => 
object(ViewErrorBag), 'robots' => object(Builder))) in View.php line 137 

at View->getContents() in View.php line 120 
at View->renderContents() in View.php line 85 
at View->render() in Response.php line 38 
+0

不完全確定你的要求,你可以給出一個例子或結果你得到和你想要的? –

+0

@Nigel仁例如,當我選擇「任何類別」,我想獲得數組的所有值,在這種情況下,類別「光」,「中」和「重」。 – Adato

回答

0

而不是試圖想出一個辦法的包括曾經就像這樣,你可以改變它來根據你選擇的限制選擇。所以

$robots = DB::table('robots')->where('Category_id', [$categoryesc])->where('Manufacturer_id', [$manufaesc])->where('Price', '<=', $priceesc)->get(); 

可以寫成

$robots = DB::table('robots'); 
if ($categoryesc !=0) { 
    $robots->where('Category_id', $categoryesc); 
} 
if ($manufaesc!=0) { 
    $robots->where('Manufacturer_id', $manufaesc); 
} 
if ($manufaesc!=0) { 
    $robots->where('Price', '<=', $priceesc); 
} 
$robots->get(); 

而在你的刀,你設置了「任何」價值爲0。因此,它僅包含一個選擇,當你需要它。

+0

謝謝。我曾想過使用這種排除的想法,但不知道如何或甚至可以完成。但是,現在即時在刀片文件中獲取此錯誤消息。出於某種原因,我無法運行與機器人有關的任何數據。我已更新了最初的帖子以包含此錯誤消息。 – Adato