Support the ongoing development of Laravel.io →
Blade Forms
Last updated 2 years ago.
0

Is tags a column in the posts table or a relationship?

0

thomastkim said:

Is tags a column in the posts table or a relationship?

is relationship

table posts id autor title content timestamps

table tags id name timestamps

table posts_tags post_id tag_id

0

I don't think there is an easy way to do this. One potential way to do this is to create a custom accessor. For example, in your Post model, you can create an accessor that will get your tags, loop through it, and generate a comma-separated value of its tags' names.

public function getTagsNameAttribute()
{
    $value = '';
    foreach ($this->tags as $tag) {
        $value .= $tag->name . ', ';
    }
    return $value;
}

Then, in your form, you just need to change it to this:

{!! Form::text('tags_name', NULL, ['class'=>'form-control']) !!}
Last updated 9 years ago.
0

Thank you Thomastkim,

I got so:

<div class="form-group">
  {!! Form::label('tags','Insert tags separated by semicolon:') !!}
  {!! Form::text('tags',  implode(' ', $post->tags->lists('name')->toArray()) , ['class'=>'form-control']) !!}
</div>
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.