Replies: 3 comments 9 replies
-
@Mishanki have you tried adding a
to the ::create array? Edit: wait, I'm misremembering. Let me look at my code and I'll follow up. |
Beta Was this translation helpful? Give feedback.
-
Yeah I think the sample documentation is a bit misleading in terms of how you'd actually use the functionality in practice. If you're for instance creating a new blog entry in your BlogController, you'd have something like the following code inside your create post action: $blogPost->title = $request->title;
$blogPost->tag = Tag::findOrCreate($request->tag, 'myDefaultTagType'); You're essentially hard-coding the tag type in the controller. |
Beta Was this translation helpful? Give feedback.
-
Hmm, try passing Tag::findOrCreate a string then, as it looks like it's being passed a null value. $data['tags'] = Tag::findOrCreate('this is the name of a tag', 'this-is-the-type-of-the-tag'); That's pretty well straight out of the docs. |
Beta Was this translation helpful? Give feedback.
-
This example create tag without type. Can I set default type for NewsItem model?
Beta Was this translation helpful? Give feedback.
All reactions