9.2. 边栏资源推荐
资源推荐
接下来我们将开发右边栏的资源推荐区块,并允许站长在后台对此块内容进行编辑。因为推荐资源数据属于极少修改的数据,我们还会使用缓存来为加速读取。
1. 生成数据模型
我们为资源推荐模型取名 Link
,使用命令行新建模型,顺便创建数据库迁移:
$ php artisan make:model Models/Link -m
修改数据库迁移文件为以下:
{timestamp}_create_links_table
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateLinksTable extends Migration
{
public function up()
{
Schema::create('links', function (Blueprint $table) {
$table->increments('id');
$table->string('title')->comment('资源的描述')->index();
$table->string...