2017-05-08 2 views
0

こんにちは、私はどのように "選択"のすべての可能な値を取得する "オプション"を作成する方法を知りたいです。私はwhereInとwhereBetwenを試しましたが、それを得ることはできません。誰かがそれについてJqueryを使って言及しました。ララベル版は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 Renの例では、「すべてのカテゴリ」を選択すると、配列のすべての値を取得したいとします。この場合はカテゴリ「Light」、「Medium」および「Heavy」です。 – 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

ありがとうございます。私は排除するという考えを使って考えましたが、それがどうやってどうやって行えたかは分かりませんでした。しかし、今は、このエラーメッセージをブレードファイルで取得しています。何らかの理由で、foreach内のロボットに関連するすべてのデータを実行できません。私はこのエラーメッセージを含める最初の投稿を更新しました。 – Adato

関連する問題