我正在使用Laravel创建一个网络机器人,它从其他网站收集数据并将其存储在我的MySQL数据库中。当我想要保存body
时,我使用dd($this->render($post));
,这很好。然而,当我使用$post->save()
保存我的文章在分贝,它不完全保存我的文章的正文和一些文本丢失。laravel保存方法不完全保存数据
我的body
至少有10000个字符,我总是有这个问题。
我检查身体柱式text
和longtext
和不存在任何区别...
在哪里的问题?
编辑:
这是我的索引方法:
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');
}
}
你的模型是否有'$ fillable'属性,并且是它的内部属性? [docs](http://laravel.com/docs/5.1/eloquent#mass-assignment) –
TEXT 65,535字节,LONGTEXT 4,294,967,295字节〜4GB ...对我来说看起来有点不同....并且注意是__byte__大小,而不是字符大小 –
在你调用'save'方法之前,你可以发布模型创建/提取和列分配的代码的其余部分。问题可能在于此。 – Bogdan