Answer the question
In order to leave comments, you need to log in
Why is Eloquent communication not working?
Good afternoon
There are 3 tables:
PM
Event
SnPmContact
Made connections in the models:
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class PM extends Model
{
public $timestamps = false;
public function events()
{
return $this->hasMany(Event::class, 'pm_id', 'PODE');
}
public function contacts()
{
return $this->hasMany(SnPmContact::class, 'PODE_PM', 'PODE');
}
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Event extends Model
{
public function pm(): BelongsTo
{
return $this->belongsTo(PM::class, 'pm_id', 'PODE');
}
public function contacts(): BelongsTo
{
return $this->belongsTo(SnPmContact::class, 'pm_id', 'PODE_PM');
}
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class SnPmContact extends Model
{
public function pm(): BelongsTo
{
return $this->belongsTo(PM::class, 'PODE_PM', 'PODE');
}
public function events()
{
return $this->belongsTo(Event::class, 'PODE_PM', 'pm_id');
}
}
App\Models\SnPmContact::select(['PODE_PM', 'USER_NAME'])->with(['pm:PODE'])->get()
type PM {
ID: Int
PODE: Int
NAMEPM: String
NAME2PM: String
TIME_ZONE: Int
contacts: [SnPmContact]
events: [Event]
}
type SnPmContact {
PODE_PM: Int
USER_NAME: String
USER_POST: String
pm: PM
events: [Event]
}
type Event {
id: Int!
pm_id: Int!
start_time: DateTime
status: Int
type: Int
log_text: String
created_at: DateTime
updated_at: DateTime
pm: PM
contacts: [SnPmContact]
}
type Query {
contactsByPodePM(PODE_PM: Int! @where): [SnPmContact] @all
}
{
"message": "Internal server error",
"extensions": {
"category": "internal"
},
"locations": [
{
"line": 4,
"column": 5
}
],
"path": [
"contacts",
0,
"pm"
]
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question