5.4. 问题模型的发布属性
本节说明
在本节,我们给Question
问题模型添加一个是否发布的属性,并且用户只能浏览跟回答已发布的问题,而不能对未发布的问题进行操作。
修改测试
首先我们需要修改ViewQuestionsTest.php
文件,修改测试方法(注意顶部 use Carbon\Carbon;
):
tests/Feature/ViewQuestionsTest.php
<?php
namespace Tests\Feature;
use App\Models\Question;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;