You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello to all!
Sorry, I got a pretty damn simple situation but I’m not able to find a solution or a sample by myself.
This is my scenario: I got 2 models, a pivot table and a Crud Resource
Mountain
id - standard table id
name - mountain name
mountain_ccid - unique string identifier
Comune (that means Municipality)
id - standard table id
name - comune name
comune_ccid - unique string identifier
Comune_Mountain (pivot table)
id - standard table id
mountain_ccid - mountain unique identifier
coume_ccid - comune unique identifier
I got 2 manytomany relation on Models:
On Comune Model:
public function mymountains(){
return $this->belongsToMany(Mountain::class,'comune_mountain','comune_ccid','mountain_ccid','CCID','CCID')
->orderByPivot('mountains.altitude','desc');
}
On Mountain Model:
public function mycomuni(){
return $this->belongsToMany(Comune::class,'comune_mountain','mountain_ccid','comune_ccid','CCID','CCID');
}
These relations works pretty well when used in Laravel standar views (also using “lazy loading”)
Well, I create a resource using:
php artisan orchid:resource ComuneResource
And using on it :
public function fields(): array
{
return [
…..
Relation::make('mountain_ccid.')
->horizontal()
->fromModel(Mountain::class, 'name')
->multiple()
->title('Montain'),
…..
];
}
I was able to load all Mountain names and have multiple selection BUT:
I’m not able to pre-select the mountains that are already in pivot table
I’m not able to edit/insert in pivot table
Basically - and sadly - I’m not able to manage the relation at all…
Could someone give me some advice or show me a working sample?
I just found an italian Blog Post about it, but I’m not able to make it work using keys different form Id.
Thanx in advance!
Davide
===Update===
I try to edit the accesskey using the relations:
Relation::make('comune.mymountains.mountain_ccid.')
but i got a strange behaviour: the resource edit the comune name field with something like this:
{"mymountains":{"mountain_ccid":["1","3","5"]}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello to all!
Sorry, I got a pretty damn simple situation but I’m not able to find a solution or a sample by myself.
This is my scenario: I got 2 models, a pivot table and a Crud Resource
Mountain
Comune (that means Municipality)
Comune_Mountain (pivot table)
I got 2 manytomany relation on Models:
On Comune Model:
public function mymountains(){
return $this->belongsToMany(Mountain::class,'comune_mountain','comune_ccid','mountain_ccid','CCID','CCID')
->orderByPivot('mountains.altitude','desc');
}
On Mountain Model:
public function mycomuni(){
return $this->belongsToMany(Comune::class,'comune_mountain','mountain_ccid','comune_ccid','CCID','CCID');
}
These relations works pretty well when used in Laravel standar views (also using “lazy loading”)
Well, I create a resource using:
php artisan orchid:resource ComuneResource
And using on it :
public function fields(): array
{
return [
…..
Relation::make('mountain_ccid.')
->horizontal()
->fromModel(Mountain::class, 'name')
->multiple()
->title('Montain'),
…..
];
}
I was able to load all Mountain names and have multiple selection BUT:
Basically - and sadly - I’m not able to manage the relation at all…
Could someone give me some advice or show me a working sample?
I just found an italian Blog Post about it, but I’m not able to make it work using keys different form Id.
Thanx in advance!
Davide
===Update===
I try to edit the accesskey using the relations:
Relation::make('comune.mymountains.mountain_ccid.')
but i got a strange behaviour: the resource edit the comune name field with something like this:
{"mymountains":{"mountain_ccid":["1","3","5"]}}
Beta Was this translation helpful? Give feedback.
All reactions