Merhaba ,
Blog sistemim için tag sistemi oluşturmaya çalışıyorum. Şu ana kadar typeahead ile önerileri aldırmayı başardım. Sadece yazarak girilen listede tagları ayırarak database kaydı olmayanları ekleyen bir sistem oluşturdum. makaleyi oluştururken sistem sorunsuz çalışıyor.
Makale editlerken ise tekrar synch ederken sorun çekiyorum. post_tags tablosuna "id"leri değl de "name" kolonunu ekliyor.
Kodlarım ise form da
<input type="text" data-provide="typeahead" value="{{ Input::old('tags', $theTags) }} class="typeahead" data-items="1" name="tags" "/>
public function postEdit($postId = null)
{
$theTags=array();
$tags = explode(',', Input::get('tags'));
//check if tag exists in db
foreach ($tags as $key=>$value){
$dbtag = Tag::where('name', '=', $value)->first();
array_push($theTags, $dbtag);
//add to db
if(!$dbtag){
$dbtag = new Tag;
// Update the tag
$dbtag->name= e(ucwords($value));
$dbtag->slug = e(Str::slug($value));
$dbtag->save();
array_push($theTags, $dbtag);
}
}
// Update the blog post data
$post->title = e(Input::get('title'));
$author = Author::find(Input::get('author_id'));
// Was the blog post created?
if($author->posts()->save($post))
{
$post->categories()->sync(Input::get('categories'));
$post->tags()->sync(Input::get('tags'));
// Redirect to the new blog post page
return Redirect::to("admin/blogs/$postId/edit")->with('success', Lang::get('admin/blogs/message.update.success'));
}
}
Pivot tabloyu nasıl doğru olarak synch edebilirim ?