Laravel 5.7 where + diff

ルカシン

問題は、show.blade.phpにすでにそのid=1アイテムがあるため、diffを使用したいということです。次に、そのアイテムをスキップして取る方法。

 public function show($id){
 $product = Product::findOrFail($id);
 $collection = Product::where('request_register',$product->request_register)->diff('request_register',$product->request_register)->get();
    return view('products.show', compact('product','collection'));
}

エラーは次のとおりです。

未定義のメソッドIlluminate \ Database \ Eloquent \ Builder :: diff()の呼び出し

カルス

diff()メソッドを定義したIlluminate\Database\Eloquent\Collection、あなたはメソッドを呼び出す必要がget()呼び出す前にdiff()方法を。

public function show($id){
    $product = Product::findOrFail($id);
    $collection = Product::where('request_register', $product->request_register)
        // Call get() to return Illuminate\Database\Eloquent\Collection.
        ->get()
        ->diff('request_register',$product->request_register);
    return view('products.show', compact('product','collection'));
}

見る:

Illuminate \ Database \ Eloquent \ Builder | Laravel API

Illuminate \ Database \ Eloquent \ Collection | Laravel API

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Laravel 5 Eloquent where and or in Clauses

分類Dev

Laravel 5 - where to place reusable custom validator?

分類Dev

Where to place FormRequest logging in Laravel 5?

分類Dev

Laravel 5 Eloquent ORM select where --array as parameter

分類Dev

Where in Laravel 5 should I place initial service providers calls?

分類Dev

GodaddyCORSの問題-Angular7-Laravel 5

分類Dev

Laravel Where In on Where Has

分類Dev

( (Where and Where) OR (Where and Where) ) Laravel 5.2

分類Dev

Laravel 7クエリwith()およびWhere()の使用

分類Dev

Laravel5とQueryBuilderで "OR WHERE YEAR(...)句を書く方法は?

分類Dev

Laravel 5where句を別のテーブルから

分類Dev

Laravel 5:雄弁に「where」または「orderBy」を使用する方法は?

分類Dev

Laravel5クエリ「where(a OR b OR c)AND(d OR e OR f)AND ...(x OR y OR z)」

分類Dev

Laravel5。複合主キー。'where句'の不明な列 'id'

分類Dev

Laravel Homestead php-7 "php5-fpm:unrecognized service" on vagrant up

分類Dev

Laravel With()とWhere()

分類Dev

Laravel Eloquent "WHERE NOT IN"

分類Dev

Laravel hasMany with where

分類Dev

Laravel Eloquent - Where In All

分類Dev

Eloquent Laravel Where And Or And

分類Dev

Laravel whereDate and where

分類Dev

Laravel Where Count> N

分類Dev

Multiple where clause, Laravel

分類Dev

Laravel LeftJoin where

分類Dev

Laravel: Fetch with where filter on "with"

分類Dev

Laravel 4 eloquent WHERE with AND and OR?

分類Dev

Laravel Where と OrWhere

分類Dev

Laravel where句 timediff

分類Dev

Laravel with where 雄弁