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
I've struggled a little getting started with this framework, especially when it comes to documentation of the relation fields.
In [https://orchid.software/en/docs/field/#relation](the docs), relations are mentioned as standalone, like this.
Relation::make('idea')
->fromModel(Idea::class, 'name')
->title('Choose your idea');
For me, this will leave an empty relation field that fails silently.
I've since learned that in my projects, I have to do something like this:
Relation::make('user.idea')
->fromModel(Idea::class, 'name')
->title('Choose your idea');
Since the relation appears on a page belonging to another model.
I don't mind adding a PR with a suggestion for how to reflect this in the docs but wanted to gather feedback beforehand, as I don't have a lot of experience contributing to public repos.
The text was updated successfully, but these errors were encountered:
Hi @TobiasPalludan, I think it depends on the context. To make it clearer, it can be compared as follows.
When writing:
Relation::make('idea')
->fromModel(Idea::class, 'name')
->title('Choose your idea');
The resulting HTML will be:
<label>Choose your idea</label><selectname="idea"><optionvalue="...">...</option></select>
When changing to Relation::make('user.idea'), the resulting HTML will change to <select name="user[idea]">.
They both work fine. However, I usually work with some entity (for example, an Eloquent model) and I want to put as little pressure on it as possible, so I use a prefix that clarifies what it is, for example, "user." and "products.".
It's not necessary to use a prefix. Instead of returning a model with a key in the query method, you can return the model attributes, for example:
publicfunctionquery(): iterable
{
returnUser::first()->toArray();
}
// and usage Input::make('name')
I prefer the first method because when you need to modify the screen by adding new entities to it, it will be easy and won't lead to changes in layers. Let me know if you have any questions.
tabuna
transferred this issue from orchidsoftware/orchid.software
Jun 19, 2023
I've struggled a little getting started with this framework, especially when it comes to documentation of the relation fields.
In [https://orchid.software/en/docs/field/#relation](the docs), relations are mentioned as standalone, like this.
For me, this will leave an empty relation field that fails silently.
I've since learned that in my projects, I have to do something like this:
Since the relation appears on a page belonging to another model.
I don't mind adding a PR with a suggestion for how to reflect this in the docs but wanted to gather feedback beforehand, as I don't have a lot of experience contributing to public repos.
The text was updated successfully, but these errors were encountered: