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
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']) !!}
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>
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community