What about the database?

|
mazcvei 2022-09-14 22:57:51
mazcvei 2022-09-14 22:48:34
$requests[2]->departament is null

😉

mazcvei 2022-09-14 22:58:42
mazcvei 2022-09-14 22:57:51
😉

the third object has no department relationship

Manalalsubaei 2022-09-14 22:58:57
mazcvei 2022-09-14 22:57:51
😉

what about the database?!

DesolatorMagno 2022-09-14 22:58:57
laravel_discuss-138337.jpg
Not object doesn’t mean null, just that is not a object.
DesolatorMagno 2022-09-14 22:59:09
Show the model relationship.
mazcvei 2022-09-14 22:59:14
Manalalsubaei 2022-09-14 22:58:57
what about the database?!

wrong relationship construction, assignation

DesolatorMagno 2022-09-14 23:00:02
mazcvei 2022-09-14 22:59:14
wrong relationship construction, assignation

Exactly, it could even be a field in database with that name that do conflict with the relationshio.

Manalalsubaei 2022-09-14 23:00:06
DesolatorMagno 2022-09-14 22:59:09
Show the model relationship.

laravel_discuss-138342.jpg

Manalalsubaei 2022-09-14 23:00:19
laravel_discuss-138343.jpg

mazcvei 2022-09-14 23:00:32
Manalalsubaei 2022-09-14 23:00:06
laravel_discuss-138342.jpg

add foregein key and local key

mazcvei 2022-09-14 23:01:24
Manalalsubaei 2022-09-14 23:00:06
laravel_discuss-138342.jpg

model has not $table & $fillable properties

mazcvei 2022-09-14 23:02:07
Manalalsubaei 2022-09-14 23:00:19
laravel_discuss-138343.jpg

https://laravel.com/docs/9.x/eloquent-relationships read doc about relationships

Laravel – The PHP Framework For Web ArtisansLaravel
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
DesolatorMagno 2022-09-14 23:02:22
PurchaseRequest::first()->department()->toSql()

That give you the sql that run, and you can see what name for foraign id it expect.

DesolatorMagno 2022-09-14 23:04:32
You can either change the name to departments_id (almost sure that is what it expect) or just expecify the f key.
Manalalsubaei 2022-09-14 23:07:17
mazcvei 2022-09-14 23:01:24
laravel_discuss-138343.jpg
model has not $table & $fillable properties

$fillable I wrote it

Manalalsubaei 2022-09-14 23:14:47
mazcvei 2022-09-14 23:01:24
laravel_discuss-138343.jpg
model has not $table & $fillable properties

laravel_discuss-138353.jpg

mazcvei 2022-09-14 23:15:04
Manalalsubaei 2022-09-14 23:14:47
laravel_discuss-138353.jpg

add fk & local key

Alexkddd 2022-09-14 23:15:20
We are looking for blockchain developer, He must have knowledge of moralis .
Manalalsubaei 2022-09-14 23:15:42
mazcvei 2022-09-14 23:15:04
laravel_discuss-138353.jpg
add fk & local key

in side $fillable ?

mazcvei 2022-09-14 23:15:46
Manalalsubaei 2022-09-14 23:15:42
laravel_discuss-138353.jpg
in side $fillable ?

no

mazcvei 2022-09-14 23:15:56
mazcvei 2022-09-14 23:02:07
laravel_discuss-138353.jpg
https://laravel.com/docs/9.x/eloquent-relationships read doc about relationships

read

Manalalsubaei 2022-09-14 23:16:55
okey.
but i use this way and work very well
Manalalsubaei 2022-09-14 23:17:16
mazcvei 2022-09-14 23:15:46
laravel_discuss-138353.jpg
no

in side megration

Manalalsubaei 2022-09-14 23:24:12
DesolatorMagno 2022-09-14 23:02:22
laravel_discuss-138353.jpg
PurchaseRequest::first()->department()->toSql()

That give you the sql that run, and you can see what name for foraign id it expect.

laravel_discuss-138361.jpg

DesolatorMagno 2022-09-14 23:24:33
so, you see the problem?
Manalalsubaei 2022-09-14 23:27:42
mazcvei 2022-09-14 23:15:04
laravel_discuss-138353.jpg
add fk & local key

laravel_discuss-138364.jpg

Manalalsubaei 2022-09-14 23:29:08
DesolatorMagno 2022-09-14 23:24:33
laravel_discuss-138353.jpg
so, you see the problem?

I don’t know?

DesolatorMagno 2022-09-14 23:30:14
the Fk have a different name that what Laravel expect, so you need to specify the name, you have deparment_id it expect departments_id
Manalalsubaei 2022-09-14 23:34:54
laravel_discuss-138367.jpg

Manalalsubaei 2022-09-14 23:46:22
DesolatorMagno 2022-09-14 23:30:14
laravel_discuss-138353.jpg
the Fk have a different name that what Laravel expect, so you need to specify the name, you have deparment_id it expect departments_id

laravel_discuss-138368.jpg

Manalalsubaei 2022-09-14 23:46:35
mazcvei 2022-09-14 23:15:04
laravel_discuss-138353.jpg
add fk & local key

I added it.

Manalalsubaei 2022-09-14 23:47:32
but no use
DesolatorMagno 2022-09-14 23:48:58
DesolatorMagno 2022-09-14 23:02:22
laravel_discuss-138353.jpg
PurchaseRequest::first()->department()->toSql()

That give you the sql that run, and you can see what name for foraign id it expect.

Do these again and see if it changed

Manalalsubaei 2022-09-14 23:50:40
laravel_discuss-138372.jpg

DesolatorMagno 2022-09-14 23:52:34
You know that deparment relationship is the one that you are trying to access, right?
|