filmov
tv
Create a CRUDs for all your database tables in seconds using Laravel and Laravel-Code-Generator

Показать описание
In this screencast we go through multiple command offered by Laravel-Code-Generator package. We created a very simple "Music Library" app using database-first approach using Laravel 5.5 and the awesome Laravel-Code-Generator v2.2.2!
If you like this screencast please give me a thumbs up, and share it with the community to increase awareness.
### Steps Used during the screencast
In this tutorial, I am going to assume that you watched the previous screencast, and already have the schema created. But if you did not, you can use the SQL script below to generate the tables.
To get started, I used the following command to create the first resource-file for my existing "singers" table
php artisan resource-file:from-database Singer
php artisan create:resources Singer
The next command allowed us to perform both steps listed above using one command
php artisan create:resources Singer --table-exists --force
php artisan resource-file:from-database SongCategory
php artisan resource-file:from-database Song
php artisan create:mapped-resources
Here is the SQL script needed to create the databases tables.
CREATE TABLE `singers` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`gender` enum('male','female') COLLATE utf8mb4_unicode_ci NOT NULL,
`music_type` enum('country','pop','rock','jazz','rap') COLLATE utf8mb4_unicode_ci NOT NULL,
`is_retired` tinyint(1) NOT NULL,
`notes` varchar(1000) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `song_categories` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `songs` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`album` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`singer_id` int(10) unsigned NOT NULL,
`release_year` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`song_category_id` int(10) unsigned NOT NULL,
`file` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
KEY `songs_singer_id_index` (`singer_id`),
KEY `songs_song_category_id_index` (`song_category_id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
If you like this screencast please give me a thumbs up, and share it with the community to increase awareness.
### Steps Used during the screencast
In this tutorial, I am going to assume that you watched the previous screencast, and already have the schema created. But if you did not, you can use the SQL script below to generate the tables.
To get started, I used the following command to create the first resource-file for my existing "singers" table
php artisan resource-file:from-database Singer
php artisan create:resources Singer
The next command allowed us to perform both steps listed above using one command
php artisan create:resources Singer --table-exists --force
php artisan resource-file:from-database SongCategory
php artisan resource-file:from-database Song
php artisan create:mapped-resources
Here is the SQL script needed to create the databases tables.
CREATE TABLE `singers` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`gender` enum('male','female') COLLATE utf8mb4_unicode_ci NOT NULL,
`music_type` enum('country','pop','rock','jazz','rap') COLLATE utf8mb4_unicode_ci NOT NULL,
`is_retired` tinyint(1) NOT NULL,
`notes` varchar(1000) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `song_categories` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `songs` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`album` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`singer_id` int(10) unsigned NOT NULL,
`release_year` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`song_category_id` int(10) unsigned NOT NULL,
`file` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
KEY `songs_singer_id_index` (`singer_id`),
KEY `songs_song_category_id_index` (`song_category_id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
Комментарии