PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun May 28, 2017 1:29 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sun Apr 23, 2017 2:47 pm 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 317
I have a table Admin(should have actully named it articles :P ) with the following fields:

Syntax: [ Download ] [ Hide ]
ID
title
keywords
blog_content
tag
filePath
slug
created_at
updated_at


And Then i have the Tags table with the following feilds:

Syntax: [ Download ] [ Hide ]
Id
tag


Now i want to create a hasMany relationship between the Admin and the Tags table. How do i do this ? I mean which field in the Admin table will be the foreign key ? i believe usually the foreign key is always the ID field , even the docs show the same: HERE --> https://laravel.com/docs/5.4/migrations#foreign-key-constraints , or should can i make the tag feild in the Admin table as the foreign key to the ID in the Tags table ?

I still have a scrambled brain about this issue and hence i taught it would be best to ask here, can somebody please give me a bit more clarity on this topic ?

Thank you.
Gautam.


Top
 Profile  
 
PostPosted: Sun Apr 23, 2017 4:29 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6243
Location: Montreal, Canada
Why do you have a tag field in the admin table? (and yes, you should change that table name)

If you're setting up a has and belongs to many (ie. an article can have many tags, a tag can belong to many articles), then you'll want a pivot table for both IDs. See https://laravel.com/docs/5.4/eloquent-r ... ny-to-many

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Tue Apr 25, 2017 4:42 pm 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 317
OK Thanks celaurian ! :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group