Relationship
One-to-one relationship
The users
table and the above posts
table are one-to-one associations, which are associated by the posts.author_id
field. The users
table structure is as follows:
The model is defined as:
Then you can show the details of the user to which post
belongs in the following way:
The $author
object is also a Show
instance. You can also use the various methods above.
Note: In order to be able to use the tool in the upper right corner of this panel, you must set the url access path of the user resource with the
setResource()
method.
One-to-many or many-to-many relationship
The associated data for a one-to-many or many-to-many relationship will be presented as Model-grid
. Below is a simple example.
The posts
table and the comment table comments
are one-to-many relationships (a post
has multiple comments
), associated with the comments.post_id
field.
The model is defined as:
Then the display of the comment is implemented by the following code:
$comments
is an instance of Ezadev\Admin\Grid
. For detailed usage, please refer to model-grid
Note: In order to be able to use this data table function normally, you must use the
resource()
method to set the url access path of thecomments
resource.
Last updated