i'm using Laravel 6
i have 2 tables (layanans and objeks), when i want to select a field from 'layanans' into 'objeks', i got this error message:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'layanans.objek_id_object' in 'where clause' (SQL: select * from layanans
where layanans
.objek_id_object
= 2 and layanans
.objek_id_object
is not null)
layanan table
id_layananbigint(20) unsigned NOT NULL
nama_layananvarchar(150) NOT NULL
created_attimestamp NULL
updated_attimestamp NULL
objek table
id_objectbigint(20) unsigned NOT NULL
layanan_idbigint(20) unsigned NOT NULL
tipe_objectvarchar(255) NOT NULL
created_attimestamp NULL
updated_attimestamp NULL
Objek model
<?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');
}
}
Layanan model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Layanan extends Model
{
protected $fillable=[
'nama_layanan'
];
protected $primaryKey = 'id_layanan';
}
Controller
<?php
namespace App\Http\Controllers;
use App\Layanan;
use App\Objek;
use Illuminate\Http\Request;
class Pages extends Controller
{
public function object(){
$objek = \App\Objek::all();
return view ('pages.alat.object.object')->with('data',$objek);
}
}
what is the problem?