i have 2 tables in SQL Server (MSSQL) with coloumns
table account
[id] [binary](13) NOT NULL, [PRIMARI KEY]
[email] [varchar](50) NOT NULL,
....
table status
[numG] [int NOT NULL,
[id] [binary](13) NOT NULL, [PRIMARI KEY]
[contractname] [varchar](50) NOT NULL,
....
here is relation in AccountModel :
public function status(): BelongsTo
{
return $this->BelongsTo(StatusModel::class, 'id', 'id');
}
StatusModel :
public function account(): HasOne
{
return $this->HasOne(AccountModel::class, 'id', 'id');
}
in CheckController :
public function checkStatus($id) {
$account= AccountModel::where('id', DB::raw("convert(binary(13), '$id')"))->with('status')->first();
dd($account)
}
thats returning null :
#attributes: array:21 [▼
"id" => "testUserx00x00x00x00x00x00x00x00x00x00"
"email" => "[email protected]"
]
#relations: array:1 [▼
"account" => null
]
i have try to print using eloquent
dd($account->status->numG)
its return error :
Attempt to read property "numG" on null
i want search data by id from table account and get numG from table status.
some like this
$data = [
"id" => $account->id,
"email" => $account->email
"numG" => $account->status->numG
]
any suggestion to handle binary data from SQL Server in Laravel ?