2015-11-05 32 views
0

我正在使用Laravel創建一個網絡機器人,它從其他網站收集數據並將其存儲在我的MySQL數據庫中。當我想要保存body時,我使用dd($this->render($post));,這很好。然而,當我使用$post->save()保存我的文章在分貝,它不完全保存我的文章的正文和一些文本丟失。laravel保存方法不完全保存數據

我的body至少有10000個字符,我總是有這個問題。

我檢查身體柱式textlongtext和不存在任何區別...

在哪裏的問題?

編輯:

這是我的索引方法:

public function getIndex() 
    { 
     $temp = App\Temp::where('status' , 0)->orderBy('id' , 'desc')->first(); 
     $temp->status = 1; 
     $temp->save(); 
     $post = new App\Post; 
     $post->title = $temp->title; 
     $post->link = $temp->link; 
     $post->desc = $temp->desc; 
     $post->cat_id = $temp->cat_id; 
     $post->url_id = $temp->url_id; 
     $post->body = $this->render($post); 
     $post->save(); 
     echo "+"; 
    } 

當我使用dd($this->render($post));保存前,表示沒有任何問題,全文...但保存後,當我取了身體,一些字符從帖子的末尾失蹤......

,這是render()方法...

public function render($post) 
    { 
     echo "Start : "; 
     $this->ftp->createFolder('/'.$post->url_id.'/'.$post->id."/"); 
     echo "Dir - "; 
     $mixed_body = $this->desc($post->title); 
     echo "Mix - "; 
     $body =""; 
     $body = $body . '<h3><a href='.$this->postUrl.'>'.$this->postTitle.'</a></h3>'; 
     echo "Title - "; 

     while(strlen($mixed_body) > 100) 
     { 
      $body = $body . $this->randImage($post); 
      $body = $body . $this->randTitle(); 

      //insert a random paragraph 
      $number = rand(100 , strlen($mixed_body));//temporary 
      $paragraph = substr($mixed_body , 0 , $number); 
      $mixed_body = substr($mixed_body , $number , strlen($mixed_body)-$number); 

      $body = $body . '<p>' . $paragraph . '</p>'; 
      echo "P|"; 
     } 
     echo "\nDone : ".strlen($body); 
     return $body; 
    } 

render()中的其他方法正在將一些文本附加到$body,這些並不重要。

和我的模型:

<?php namespace App; 

use Illuminate\Database\Eloquent\Model; 

class Post extends Model { 

    public function tags() 
    { 
     return $this->hasMany('App\Tag'); 
    } 

} 
+0

你的模型是否有'$ fillable'屬性,並且是它的內部屬性? [docs](http://laravel.com/docs/5.1/eloquent#mass-assignment) –

+0

TEXT 65,535字節,LONGTEXT 4,294,967,295字節〜4GB ...對我來說看起來有點不同....並且注意是__byte__大小,而不是字符大小 –

+0

在你調用'save'方法之前,你可以發佈模型創建/提取和列分配的代碼的其餘部分。問題可能在於此。 – Bogdan

回答

0

我發現我的問題的原因...... 有時我喜歡在我的身體字符laravel其後不要保存字符... 我發現使用這行刪除 字符...

$ post-> body = mb_convert_encoding($ this-> render($ post),'UTF-8','UTF-8');從所有

感謝幫助我,我有一個非常壞的頭痛,想休息......從所有再次,良好的夜間/上午/下午

感謝(根據您的時區):)