laravel belongsToMany和hasMany用法解析
阿新 • • 發佈:2019-02-15
CREATE TABLE `questions` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(10) unsigned NOT NULL,
`title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '標題',
`body` text COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '問題內容',
`flowers_count` int(11) NOT NULL DEFAULT '0' COMMENT '關注的數目' ,
`comments_count` int(11) NOT NULL DEFAULT '1' COMMENT '評論的數目',
`close_comment` varchar(8) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'F' COMMENT '評論的狀態 F可以評論 T關閉評論',
`is_hidden` varchar(8) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'F' COMMENT '問題狀態 F正常 T隱藏刪除',
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`answers_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '回答的數量',
PRIMARY KEY (`id`),
KEY `questions_user_id_foreign` (`user_id`),
CONSTRAINT `questions_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;