Hướng dẫn tạo Form Contact đơn giản với Laravel
Laravel + Bảng contact + cấu hình kết nối tới database
CREATE TABLE `tld_contact` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`subject` varchar(255) NOT NULL,
`content` text,
`is_read` tinyint(1) NOT NULL DEFAULT '0',
`fullname` varchar(100) NOT NULL COMMENT 'ho ten nguoi gui lien he',
`email` varchar(255) NOT NULL,
`phone_number` varchar(15) DEFAULT NULL,
`address` varchar(15) DEFAULT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
`product_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
1. Tạo controller
php artisan make:controller --plain Frontend\ContactController
Hàm này sẽ giúp tạo ra 1 controller: app\Http\Controllers\Frontend\ContactController.phpVới đầy đủ các hàm có thể tương tác với 1 đối tượng: index, create, store, edit, show, edit, destroy
Ở đây sẽ dùng đến 2 hàm: create & store để xử lý việc hiển thị form contact và xử lý lưu contact vào DB