我制作了许多数据库应用程序,在我的数据库中具有相同的表名和相同的文件。我怎样才能显示所有数据
这是我的模型
这是我的模型用户
class Users extends Model
{
// protected $connection = 'mysql4';
protected $table = ('ilkom_akbar.table_users');
protected $primaryKey = 'ID';
protected $fillable = [
'ID',
'user_login',
'user_pass',
'user_nicename',
'user_email',
'url',
'user_registered',
'user_activation_key',
'user_status',
'display_name'
];
public function posts()
{
return $this->hasMany(Posts::class,'post_author');
}
}
这是我的模型 users1
class Users1 extends Model
{
protected $table = 'ilkom_adeputra.table_users';
protected $primaryKey = 'ID';
protected $fillable = [
'ID',
'user_login',
'user_pass',
'user_nicename',
'user_email',
'url',
'user_registered',
'user_activation_key',
'user_status',
'display_name'
];
public function posts()
{
return $this->hasMany(Posts1::class,'post_author');
}
}
这是我的模特帖子
class Posts extends Model
{
protected $table = 'ilkom_akbar.table_posts';
protected $primaryKey = 'ID';
protected $fillable = [
'ID',
'post_author',
'post_date',
'post_date_gmt',
'post_content',
'post_title',
'post_excerpt',
'post_status',
'comment_status',
'ping_status',
'post_password',
'post_name',
'to_ping',
'pinged',
'post_modified',
'post_modified_gmt',
'post_content_filtered',
'post_parent',
'guid',
'menu_order',
'post_type',
'post_mime_type',
'comment_count'
];
public function users()
{
return $this->belongsTo(Users::class,'ID');
}
}
这是我的模特帖子1
class Posts1 extends Model
{
protected $table = 'ilkom_adeputra.table_posts';
protected $primaryKey = 'ID';
protected $fillable = [
'ID',
'post_author',
'post_date',
'post_date_gmt',
'post_content',
'post_title',
'post_excerpt',
'post_status',
'comment_status',
'ping_status',
'post_password',
'post_name',
'to_ping',
'pinged',
'post_modified',
'post_modified_gmt',
'post_content_filtered',
'post_parent',
'guid',
'menu_order',
'post_type',
'post_mime_type',
'comment_count'
];
public function users()
{
return $this->belongsTo(Users1::class,'ID');
}
}
这是获取数据
@foreach ($karyawan1->posts as $data)
<tr>
<td>{{ $no++}}</td>
<td>{{ $data->post_title}}</td>
<td>{{ $data->post_name}}</td>
<td>{{ $data->post_modified}}</td>
<td>{{ $data->post_modified_gmt}}</td>
@endforeach