简体   繁体   English

laravel-选项所有值

[英]laravel - option all values

Hi i would like to know how to create an "option" in a "select" that gets all the possible values of that "select". 嗨,我想知道如何在“选择”中创建一个“选项”,以获取该“选择”的所有可能值。 I have tried whereIn and whereBetwen, but cant get it. 我尝试了whereIn和whereBetwen,但无法获得。 Someone even mentioned using Jquery for it. 甚至有人提到使用Jquery。 The laravel version is 5.4. laravel版本是5.4。

This is the code: 这是代码:

controller 调节器

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')); 
}

blade file: 刀片文件:

{{ 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() }}

Error: 错误:

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

Rather than trying to come up with a way of including everything like this, you can change it to limit the selections according to what you select. 与其尝试提​​出一种包括所有此类内容的方法,不如对其进行更改以根据您的选择限制选择范围。 So 所以

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

Could be written as 可以写成

$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();

And in your blade, you set the 'Any' value to 0. So that it only includes a selection when you need it. 然后在刀片中,将“任何”值设置为0。这样,它仅在需要时才包含选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM