2016-08-15 75 views
0

没有什么能够找到在laravel 5.2中存储大量动态标题,子标题,项目符号和段落的复杂文本内容的最佳方法。什么是最好和最简单的方法?什么是数据库结构和存储多个标题的方法。保存帖子的标题和正文是另一回事,很容易。需要帮助......laravel在mysqli数据库中复杂的文本内容存储

回答

0

您可以使用mediumTextlongText作为您的Column ....开头;首先去你的Console并创建一个像这样的迁移:php artisan make:migration Articles。然后,一旦创建迁移文件,将其打开,然后在该文件的up()方法中添加以下行。像这样:

<?php 
    // FILE_NAME: 2016_08_15_163807_Articles.php 

    use Illuminate\Database\Migrations\Migration; 
    use Illuminate\Database\Schema\Blueprint; 

    class Articles extends Migration { 

     public function up() { 
      // Create table for storing data 
      Schema::create('articles', function (Blueprint $table) { 
       $table->increments('id'); 
       $table->string('title'); 
       $table->string('heading')->nullable(); 
       $table->string('sub_heading')->nullable(); 
       $table->string('photo')->nullable(); 
       $table->mediumText('body')->nullable(); //<== ENOUGH FOR COMPLEX TEXT 
       //$table->longText('complex_text')->nullable(); //<== MORE THAN ENOUGH FOR COMPLEX TEXT 
       $table->timestamps(); 
      }); 
     } 

然后app目录内,创建一个名为Article文件,也可以像这样通过命令行生成它:

php artisan make:model Article 

要确保在创建新表,运行:

php artisan migrate 

现在你有这将具有的属性,如titleheading的文章对象,sub_headingphotobody。但重要的是打开App\Article类并设置一个重要变量:

<?php 

    namespace App; 

    use Illuminate\Database\Eloquent\Model; 

    class Article extends Model { 

     /** 
     * The attributes that are mass assignable. 
     * 
     * @var array 
     */ 
     protected $fillable = [ 
      'title', 'heading', 'sub-heading', 'photo', 'body' 
     ]; 
    } 
+0

此行是否会在数据库中完全添加html标记?怎么运行的? – root

+0

谢谢这么多,但我知道这个东西。你写了关于迁移,这是用完整的。我想知道数据库应该如何处理这种复杂的文本内容 – root

+0

一个混淆是是否要分离所有标题和副标题,然后将所有内容保存到complex_text – root