解決したい内容:LaravelのcontrollerからModelを呼び出す際にタイトルのエラーが出てしまいます。
空のカラムを取得しようするのは何故なのでしょうか?
Laravelに詳しい方、どなたかお力貸していただけませんでしょうか。
Laravelのバージョンは5.8です。
発生しているエラー
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'items.' in 'where clause' (SQL: select * from `items` where `id` = 1 and `items`.`` is null limit 1)
該当するソースコード
controller(抜粋)
php
1use App\Models\Item; 2use App\Models\Article; 3 4class CheckController extends Controller 5{ 6 public function index(Request $request) 7 { 8 //ここは正しく取得できる 9 $test1 = Article::where('id', '20')->first(); 10 dump($test1); 11 12 //ここで上記のエラーに出る 13 $test2 = Item::where('id', '1')->first(); 14 dump($test2); 15 } 16} 17
Model
php
1<?php 2 3namespace App\Models; 4 5use App\Models\BaseModel; 6use Illuminate\Database\Eloquent\SoftDeletes; 7 8class Item extends BaseModel 9{ 10 use SoftDeletes; 11 const UPDATED_AT = null; 12 const DELETED_AT = null; 13 14 protected $guarded = [ 15 'id', 'created_at' 16 ]; 17} 18 19
回答2件
良いと思った回答にはグッドを送りましょう。
グッドが多くついた回答ほどページの上位に表示されるので、他の人が素晴らしい回答を見つけやすくなります。
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。