2017-05-08 96 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