不太能理解 fillable 的作用?
class Reply extends Model
{
protected $fillable = ['content'];
}
class RepliesController extends Controller
{
public function store(ReplyRequest $request, Reply $reply)
{
$reply->content = $request->content;
$reply->user_id = Auth::id();
$reply->topic_id = $request->topic_id;
$reply->save();
return redirect()->to($reply->topic->link())->with('success', '创建成功!');
}
}
Reply Model 这里的代码标识只有字段content
可以有用户来从前台传入修改数据库,而 RepliesController 这里实际上topic_id
也是由用户从前台传来的,这样似乎$fillable = ['content'];
感觉并没有什么意义,很难理解这部分。
推荐文章: