我正在使用Laravel 6
我有2个表(layanans和objeks),当我想从“ layanans”到“ objeks”中选择一个字段时,出现以下错误消息:
SQLSTATE [42S22]:找不到列:1054“ where子句”中的未知列“ layanans.objek_id_object”(SQL:从layanans
中选择*,其中layanans
。{{1} } = 2并且objek_id_object
。layanans
不为空)
layanan表
objek_id_object
objek表
id_layananbigint(20) unsigned NOT NULL
nama_layananvarchar(150) NOT NULL
created_attimestamp NULL
updated_attimestamp NULL
Objek模型
id_objectbigint(20) unsigned NOT NULL
layanan_idbigint(20) unsigned NOT NULL
tipe_objectvarchar(255) NOT NULL
created_attimestamp NULL
updated_attimestamp NULL
Layanan模型
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Objek extends Model
{
protected $fillable=[
'layanan_id', 'tipe_object'
];
protected $primaryKey = 'id_object';
public function layanan(){
return $this->hasMany('\App\Layanan');
}
}
控制器
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Layanan extends Model
{
protected $fillable=[
'nama_layanan'
];
protected $primaryKey = 'id_layanan';
}
出什么问题了?
答案 0 :(得分:0)
我忘了写我的foreach
object.blade.php
@foreach ($data as $item)
<tr>
<td>{!! $item->id_object !!}</td>
<td>{!! $item->layanan->nama_layanan !!}</td>
<td>{!! $item->tipe_object !!}</td>
{{-- <td>{!! $item->created_at->format('d/m/Y') !!}</td> --}}
{{-- <td>{!! $item->updated_at->format('d/m/Y') !!}</td> --}}
<td width="103px">
<div class="">
<a class="btn btn-block btn-sm btn-success col-12 d-inline" href="/pages/alat/layanan/edit/{{$item->id_layanan}}">Edit</a>
<a class="btn btn-block btn-sm btn-danger col-12 d-inline" href="/pages/alat/layanan/delete/{{$item->id_layanan}}">Hapus</a>
</div>
</td>
</tr>
@endforeach
1个id_object / tipe_object具有来自 Layanan 的自己的'nama_layanan'。但是,对象可以有很多'nama_layanan'