我正在使用Eloquent庫,並且想要連接兩個表,然後顯示結果。通過Eloquent加入表
在我的index.php,我有以下行:
$identification = $_GET['id'];
$schoolToArrangement = School::where('id', $identifikasjon)>with('arrangements')->get();
echo $skoleTilArrangement;
Ofcourse,我也有我的學校類:
<?php
use Illuminate\Database\Eloquent\Model;
require_once 'vendor/autoload.php';
class School extends Model {
protected $fillable = [ 'id', 'name', 'adress', 'picture'];
public function arrangements()
{
return $this->hasOne('Arrangement','schoolId','id');
}
}
然後,我ofcourse需要一個安排類:
<?php
use Illuminate\Database\Eloquent\Model;
require_once 'vendor/autoload.php';
class Arrangement extends Model {
protected $fillable = [ 'id', 'schoolId', 'type', 'place', 'adress'];
}
因此,我的想法是,我會做一個頁面,以顯示某些學校的某些安排。
但是,當我回聲$ skole,結果如下:
[{ 「ID」:3 「navn」: 「Westerdals校園
Brenneriveien」, 「住址」: 「Brenneriveien」, 「圖片報」: 「https://www.westerdals.no/>content/uploads/2016/10/MH-brenneriveien-vulkan-oktober-26-1->960x720.jpg」, 「安排」: > {「id」:1,「skoleId」:3,「type」:「Party」,「place」:「Nightclub」,「adress」:「Partyroad 1337」}}]
換句話說我的加入正在工作。
但是我想只顯示從排列表中收集的行,而不是在學校表中對應的行。另外,如何在加入後回顯排列表中的列?
換句話說,我如何迴應從排列表中收集的信息?
只要問一些問題是不清楚的,儘管我認爲我的問題應該是可以理解的。
謝謝!
凹凸****** **************' – CHBR