简体   繁体   中英

LARAVEL create auto relationship on models

I'm new to defining relationships and frameworks all together, I want to define and create databalse relationships on model without change by hand

for example:

Heres is the relevant information: User Table:

Table: Users
id       - int (auto increment)
user_id  - int - primarykey
username - varchar(20)

Profile Table:

Table: Profile
id    - int (auto increment) - primarykey
name  - varchar(20)

User and profile links for relationship

(Users) user_id     (Profile) id

how to create this relationship with model generator in laravel4 like with YII framework?

this can has one to one or many to many

I'm not sure how it works in Yii, but in Laravel it's pretty easy. You can find all the information you need in the documentation: http://laravel.com/docs/eloquent#querying-relations

If you don't want to create all the relationships by hand but (almost) automatically, check the question I asked 2 days ago: Laravel 4 automatically create relationships in BaseModel - using "with"-array or scopes or what? - I think it will help you with other stuff, like form validation, too

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM