{"id":799,"date":"2016-10-22T07:15:44","date_gmt":"2016-10-22T07:15:44","guid":{"rendered":"http:\/\/myprojects.advchaweb.com\/?p=799"},"modified":"2016-10-28T09:00:47","modified_gmt":"2016-10-28T09:00:47","slug":"fast-crud-with-laravel-5","status":"publish","type":"post","link":"https:\/\/myprojects.advchaweb.com\/index.php\/2016\/10\/22\/fast-crud-with-laravel-5\/","title":{"rendered":"Fast CRUD With Laravel 5"},"content":{"rendered":"<p>Source: <a href=\"https:\/\/gilacoding.com\/read\/membuat-crud-laravel-hanya-dengan-5-menit\" target=\"_blank\">https:\/\/gilacoding.com\/read\/membuat-crud-laravel-hanya-dengan-5-menit<\/a><\/p>\n<ol>\n<li>Create a new laravel project named &#8216;latihan-crud&#8217;<br \/>\nType this command: composer create-project &#8211;prefer-dist laravel\/laravel latihan-crud<\/p>\n<pre class=\"lang:default decode:true \">teddy@teddy-K43SJ:~\/Documents\/works\/laravel$ composer create-project --prefer-dist laravel\/laravel latihan-crud\r\nWarning: This development build of composer is over 60 days old. It is recommended to update it by running \"\/usr\/local\/bin\/composer self-update\" to get the latest version.\r\nInstalling laravel\/laravel (v5.3.16)\r\n  - Installing laravel\/laravel (v5.3.16)\r\n    Downloading: 100%         \r\n\r\nCreated project in latihan-crud\r\n&gt; php -r \"file_exists('.env') || copy('.env.example', '.env');\"\r\nLoading composer repositories with package information\r\nUpdating dependencies (including require-dev)\r\n  - Installing vlucas\/phpdotenv (v2.4.0)\r\n    Downloading: 100%         \r\n\r\n  - Installing symfony\/polyfill-mbstring (v1.2.0)\r\n    Loading from cache\r\n\r\n  - Installing symfony\/var-dumper (v3.1.5)\r\n    Downloading: 100%         \r\n\r\n  - Installing symfony\/translation (v3.1.5)\r\n    Downloading: 100%         \r\n\r\n  - Installing symfony\/routing (v3.1.5)\r\n    Downloading: 100%         \r\n\r\n  - Installing symfony\/process (v3.1.5)\r\n    Downloading: 100%         \r\n\r\n  - Installing psr\/log (1.0.2)\r\n    Downloading: 100%         \r\n\r\n  - Installing symfony\/debug (v3.1.5)\r\n    Downloading: 100%         \r\n\r\n  - Installing symfony\/http-foundation (v3.1.5)\r\n    Downloading: 100%         \r\n\r\n  - Installing symfony\/event-dispatcher (v3.1.5)\r\n    Loading from cache\r\n\r\n  - Installing symfony\/http-kernel (v3.1.5)\r\n    Downloading: 100%         \r\n\r\n  - Installing symfony\/finder (v3.1.5)\r\n    Downloading: 100%         \r\n\r\n  - Installing symfony\/console (v3.1.5)\r\n    Downloading: 100%         \r\n\r\n  - Installing swiftmailer\/swiftmailer (v5.4.3)\r\n    Loading from cache\r\n\r\n  - Installing paragonie\/random_compat (v2.0.3)\r\n    Downloading: 100%         \r\n\r\n  - Installing ramsey\/uuid (3.5.1)\r\n    Downloading: 100%         \r\n\r\n  - Installing jakub-onderka\/php-console-color (0.1)\r\n    Loading from cache\r\n\r\n  - Installing jakub-onderka\/php-console-highlighter (v0.3.2)\r\n    Loading from cache\r\n\r\n  - Installing dnoegel\/php-xdg-base-dir (0.1)\r\n    Loading from cache\r\n\r\n  - Installing nikic\/php-parser (v2.1.1)\r\n    Downloading: 100%         \r\n\r\n  - Installing psy\/psysh (v0.7.2)\r\n    Loading from cache\r\n\r\n  - Installing nesbot\/carbon (1.21.0)\r\n    Loading from cache\r\n\r\n  - Installing mtdowling\/cron-expression (v1.1.0)\r\n    Loading from cache\r\n\r\n  - Installing monolog\/monolog (1.21.0)\r\n    Loading from cache\r\n\r\n  - Installing league\/flysystem (1.0.32)\r\n    Downloading: 100%         \r\n\r\n  - Installing symfony\/polyfill-util (v1.2.0)\r\n    Loading from cache\r\n\r\n  - Installing symfony\/polyfill-php56 (v1.2.0)\r\n    Loading from cache\r\n\r\n  - Installing jeremeamia\/superclosure (2.2.0)\r\n    Loading from cache\r\n\r\n  - Installing doctrine\/inflector (v1.1.0)\r\n    Loading from cache\r\n\r\n  - Installing classpreloader\/classpreloader (3.0.0)\r\n    Loading from cache\r\n\r\n  - Installing laravel\/framework (v5.3.19)\r\n    Downloading: 100%         \r\n\r\n  - Installing fzaninotto\/faker (v1.6.0)\r\n    Loading from cache\r\n\r\n  - Installing hamcrest\/hamcrest-php (v1.2.2)\r\n    Loading from cache\r\n\r\n  - Installing mockery\/mockery (0.9.5)\r\n    Loading from cache\r\n\r\n  - Installing symfony\/yaml (v3.1.5)\r\n    Downloading: 100%         \r\n\r\n  - Installing sebastian\/version (2.0.0)\r\n    Downloading: 100%         \r\n\r\n  - Installing sebastian\/resource-operations (1.0.0)\r\n    Downloading: 100%         \r\n\r\n  - Installing sebastian\/recursion-context (1.0.2)\r\n    Loading from cache\r\n\r\n  - Installing sebastian\/object-enumerator (1.0.0)\r\n    Downloading: 100%         \r\n\r\n  - Installing sebastian\/global-state (1.1.1)\r\n    Loading from cache\r\n\r\n  - Installing sebastian\/exporter (1.2.2)\r\n    Loading from cache\r\n\r\n  - Installing sebastian\/environment (1.3.8)\r\n    Downloading: 100%         \r\n\r\n  - Installing sebastian\/diff (1.4.1)\r\n    Loading from cache\r\n\r\n  - Installing sebastian\/comparator (1.2.0)\r\n    Loading from cache\r\n\r\n  - Installing doctrine\/instantiator (1.0.5)\r\n    Loading from cache\r\n\r\n  - Installing phpunit\/php-text-template (1.2.1)\r\n    Loading from cache\r\n\r\n  - Installing phpunit\/phpunit-mock-objects (3.4.0)\r\n    Downloading: 100%         \r\n\r\n  - Installing phpunit\/php-timer (1.0.8)\r\n    Loading from cache\r\n\r\n  - Installing phpunit\/php-file-iterator (1.4.1)\r\n    Loading from cache\r\n\r\n  - Installing sebastian\/code-unit-reverse-lookup (1.0.0)\r\n    Downloading: 100%         \r\n\r\n  - Installing phpunit\/php-token-stream (1.4.8)\r\n    Loading from cache\r\n\r\n  - Installing phpunit\/php-code-coverage (4.0.1)\r\n    Downloading: 100%         \r\n\r\n  - Installing webmozart\/assert (1.1.0)\r\n    Downloading: 100%         \r\n\r\n  - Installing phpdocumentor\/reflection-common (1.0)\r\n    Loading from cache\r\n\r\n  - Installing phpdocumentor\/type-resolver (0.2)\r\n    Loading from cache\r\n\r\n  - Installing phpdocumentor\/reflection-docblock (3.1.1)\r\n    Downloading: 100%         \r\n\r\n  - Installing phpspec\/prophecy (v1.6.1)\r\n    Loading from cache\r\n\r\n  - Installing myclabs\/deep-copy (1.5.4)\r\n    Downloading: 100%         \r\n\r\n  - Installing phpunit\/phpunit (5.6.1)\r\n    Downloading: 100%         \r\n\r\n  - Installing symfony\/css-selector (v3.1.5)\r\n    Downloading: 100%         \r\n\r\n  - Installing symfony\/dom-crawler (v3.1.5)\r\n    Downloading: 100%         \r\n\r\nsymfony\/var-dumper suggests installing ext-symfony_debug ()\r\nsymfony\/translation suggests installing symfony\/config ()\r\nsymfony\/routing suggests installing doctrine\/annotations (For using the annotation loader)\r\nsymfony\/routing suggests installing symfony\/config (For using the all-in-one router or any loader)\r\nsymfony\/routing suggests installing symfony\/dependency-injection (For loading routes from a service)\r\nsymfony\/routing suggests installing symfony\/expression-language (For using expression matching)\r\nsymfony\/event-dispatcher suggests installing symfony\/dependency-injection ()\r\nsymfony\/http-kernel suggests installing symfony\/browser-kit ()\r\nsymfony\/http-kernel suggests installing symfony\/class-loader ()\r\nsymfony\/http-kernel suggests installing symfony\/config ()\r\nsymfony\/http-kernel suggests installing symfony\/dependency-injection ()\r\nparagonie\/random_compat suggests installing ext-libsodium (Provides a modern crypto API that can be used to generate random bytes.)\r\nramsey\/uuid suggests installing ircmaxell\/random-lib (Provides RandomLib for use with the RandomLibAdapter)\r\nramsey\/uuid suggests installing ext-libsodium (Provides the PECL libsodium extension for use with the SodiumRandomGenerator)\r\nramsey\/uuid suggests installing ext-uuid (Provides the PECL UUID extension for use with the PeclUuidTimeGenerator and PeclUuidRandomGenerator)\r\nramsey\/uuid suggests installing moontoast\/math (Provides support for converting UUID to 128-bit integer (in string form).)\r\nramsey\/uuid suggests installing ramsey\/uuid-doctrine (Allows the use of Ramsey\\Uuid\\Uuid as Doctrine field type.)\r\nramsey\/uuid suggests installing ramsey\/uuid-console (A console application for generating UUIDs with ramsey\/uuid)\r\npsy\/psysh suggests installing ext-pdo-sqlite (The doc command requires SQLite to work.)\r\nmonolog\/monolog suggests installing aws\/aws-sdk-php (Allow sending log messages to AWS services like DynamoDB)\r\nmonolog\/monolog suggests installing doctrine\/couchdb (Allow sending log messages to a CouchDB server)\r\nmonolog\/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required))\r\nmonolog\/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server)\r\nmonolog\/monolog suggests installing graylog2\/gelf-php (Allow sending log messages to a GrayLog2 server)\r\nmonolog\/monolog suggests installing mongodb\/mongodb (Allow sending log messages to a MongoDB server via PHP Driver)\r\nmonolog\/monolog suggests installing php-amqplib\/php-amqplib (Allow sending log messages to an AMQP server using php-amqplib)\r\nmonolog\/monolog suggests installing php-console\/php-console (Allow sending log messages to Google Chrome)\r\nmonolog\/monolog suggests installing rollbar\/rollbar (Allow sending log messages to Rollbar)\r\nmonolog\/monolog suggests installing ruflin\/elastica (Allow sending log messages to an Elastic Search server)\r\nmonolog\/monolog suggests installing sentry\/sentry (Allow sending log messages to a Sentry server)\r\nleague\/flysystem suggests installing league\/flysystem-aws-s3-v2 (Allows you to use S3 storage with AWS SDK v2)\r\nleague\/flysystem suggests installing league\/flysystem-aws-s3-v3 (Allows you to use S3 storage with AWS SDK v3)\r\nleague\/flysystem suggests installing league\/flysystem-azure (Allows you to use Windows Azure Blob storage)\r\nleague\/flysystem suggests installing league\/flysystem-cached-adapter (Flysystem adapter decorator for metadata caching)\r\nleague\/flysystem suggests installing league\/flysystem-copy (Allows you to use Copy.com storage)\r\nleague\/flysystem suggests installing league\/flysystem-dropbox (Allows you to use Dropbox storage)\r\nleague\/flysystem suggests installing league\/flysystem-eventable-filesystem (Allows you to use EventableFilesystem)\r\nleague\/flysystem suggests installing league\/flysystem-rackspace (Allows you to use Rackspace Cloud Files)\r\nleague\/flysystem suggests installing league\/flysystem-sftp (Allows you to use SFTP server storage via phpseclib)\r\nleague\/flysystem suggests installing league\/flysystem-webdav (Allows you to use WebDAV storage)\r\nleague\/flysystem suggests installing league\/flysystem-ziparchive (Allows you to use ZipArchive adapter)\r\nlaravel\/framework suggests installing aws\/aws-sdk-php (Required to use the SQS queue driver and SES mail driver (~3.0).)\r\nlaravel\/framework suggests installing doctrine\/dbal (Required to rename columns and drop SQLite columns (~2.4).)\r\nlaravel\/framework suggests installing guzzlehttp\/guzzle (Required to use the Mailgun and Mandrill mail drivers and the ping methods on schedules (~5.3|~6.0).)\r\nlaravel\/framework suggests installing league\/flysystem-aws-s3-v3 (Required to use the Flysystem S3 driver (~1.0).)\r\nlaravel\/framework suggests installing league\/flysystem-rackspace (Required to use the Flysystem Rackspace driver (~1.0).)\r\nlaravel\/framework suggests installing pda\/pheanstalk (Required to use the beanstalk queue driver (~3.0).)\r\nlaravel\/framework suggests installing predis\/predis (Required to use the redis cache and queue drivers (~1.0).)\r\nlaravel\/framework suggests installing pusher\/pusher-php-server (Required to use the Pusher broadcast driver (~2.0).)\r\nlaravel\/framework suggests installing symfony\/psr-http-message-bridge (Required to use psr7 bridging features (0.2.*).)\r\nsebastian\/global-state suggests installing ext-uopz (*)\r\nphpunit\/phpunit-mock-objects suggests installing ext-soap (*)\r\nphpunit\/php-code-coverage suggests installing ext-xdebug (&gt;=2.4.0)\r\nphpunit\/phpunit suggests installing phpunit\/php-invoker (~1.1)\r\nphpunit\/phpunit suggests installing ext-xdebug (*)\r\nWriting lock file\r\nGenerating autoload files\r\n&gt; Illuminate\\Foundation\\ComposerScripts::postUpdate\r\n&gt; php artisan optimize\r\nGenerating optimized class loader\r\nThe compiled class file has been removed.\r\n&gt; php artisan key:generate\r\nApplication key [base64:2uccC5SynOBfgPZAA1zWrAQRWroPmxdMxnCT0KkXSew=] set successfully.<\/pre>\n<p>&nbsp;<\/li>\n<li>Modify .env file in \/laravel\/latihan-crud\/ directory\u00a0 to set the database setting:\n<pre class=\"lang:default decode:true \">DB_CONNECTION=mysql\r\nDB_HOST=127.0.0.1\r\nDB_PORT=3306\r\nDB_DATABASE=latihan-crud\r\nDB_USERNAME=(your db username)\r\nDB_PASSWORD=(your db password)<\/pre>\n<\/li>\n<li>Create the new database &#8216;latihan-crud&#8217; on phpmyadmin<\/li>\n<li>Install new package &#8216;crud-generator&#8217; from &#8216;appzcoder&#8217;: composer require appzcoder\/crud-generator<br \/>\nDONT FORGET TO GO INTO &#8216;latihan-crud&#8217; DIRECTORY FIRST!<\/p>\n<pre class=\"lang:default decode:true\">teddy@teddy-K43SJ:~\/Documents\/works\/laravel\/latihan-crud$ composer require appzcoder\/crud-generator\r\nUsing version ^1.2 for appzcoder\/crud-generator\r\n.\/composer.json has been updated\r\nLoading composer repositories with package information\r\nUpdating dependencies (including require-dev)\r\n  - Installing appzcoder\/crud-generator (v1.2.2)\r\n    Loading from cache\r\n\r\nWriting lock file\r\nGenerating autoload files\r\n&gt; Illuminate\\Foundation\\ComposerScripts::postUpdate\r\n&gt; php artisan optimize\r\nGenerating optimized class loader\r\nThe compiled class file has been removed.<\/pre>\n<p>Look up &#8216;appzcoder&#8217; directory in \/latihan-crud\/vendor\/<\/li>\n<li>Add the new package &#8216;Appzcoder\\CrudGenerator\\CrudGeneratorServiceProvider::class&#8217; in \/config\/app.php in &#8216;providers&#8217;\n<pre class=\"lang:default decode:true \">...\r\n'providers' =&gt; [\r\n\r\n    \/*\r\n     * Laravel Framework Service Providers...\r\n     *\/\r\n    ...\r\n    Illuminate\\View\\ViewServiceProvider::class,\r\n\r\n    \/*\r\n     * Package Service Providers...\r\n     *\/\r\n\r\n    \/\/\r\n\r\n    \/*\r\n     * Application Service Providers...\r\n     *\/\r\n    ...\r\n    App\\Providers\\RouteServiceProvider::class,\r\n    Appzcoder\\CrudGenerator\\CrudGeneratorServiceProvider::class,\r\n],<\/pre>\n<p>&nbsp;<\/li>\n<li>Install another package &#8216;laravelcollective\/html&#8217;\n<pre class=\"lang:default decode:true \">teddy@teddy-K43SJ:~\/Documents\/works\/laravel\/latihan-crud$ composer require laravelcollective\/html\r\nUsing version ^5.3 for laravelcollective\/html\r\n.\/composer.json has been updated\r\nLoading composer repositories with package information\r\nUpdating dependencies (including require-dev)\r\n  - Installing laravelcollective\/html (v5.3.0)\r\n    Downloading: 100%         \r\n\r\nWriting lock file\r\nGenerating autoload files\r\n&gt; Illuminate\\Foundation\\ComposerScripts::postUpdate\r\n&gt; php artisan optimize\r\nGenerating optimized class loader\r\nThe compiled class file has been removed.<\/pre>\n<p>Then do the same with #5 to add the new package &#8216;Collective\\Html\\HtmlServiceProvider::class,&#8217; in \/config\/app.php in &#8216;providers&#8217;:<\/p>\n<pre class=\"lang:default decode:true \">'providers' =&gt; [\r\n\r\n    \/*\r\n     * Laravel Framework Service Providers...\r\n     *\/\r\n    ...\r\n    Illuminate\\View\\ViewServiceProvider::class,\r\n\r\n    \/*\r\n     * Package Service Providers...\r\n     *\/\r\n\r\n    \/\/\r\n\r\n    \/*\r\n     * Application Service Providers...\r\n     *\/\r\n    ...\r\n    Appzcoder\\CrudGenerator\\CrudGeneratorServiceProvider::class,\r\n    Collective\\Html\\HtmlServiceProvider::class,\r\n],<\/pre>\n<p>&nbsp;<\/li>\n<li>In the same file (app.php), add the new facades &#8216;Form&#8217; and &#8216;HTML&#8217; (????) in &#8216;aliases&#8217; section:\n<pre class=\"lang:default decode:true \">...\r\n'aliases' =&gt; [\r\n\r\n    ...,\r\n    'Form' =&gt; Collective\\Html\\FormFacade::class,\r\n    ...\r\n    'HTML' =&gt; Collective\\Html\\HtmlFacade::class,\r\n    ...\r\n\r\n],<\/pre>\n<\/li>\n<li>Do &#8216;composer update&#8217; to update the dependencies\n<pre class=\"lang:default decode:true\">teddy@teddy-K43SJ:~\/Documents\/works\/laravel\/latihan-crud$ composer update\r\nLoading composer repositories with package information\r\nUpdating dependencies (including require-dev)\r\nNothing to install or update\r\nGenerating autoload files\r\n&gt; Illuminate\\Foundation\\ComposerScripts::postUpdate\r\n&gt; php artisan optimize\r\nGenerating optimized class loader\r\nThe compiled class file has been removed.<\/pre>\n<\/li>\n<li>Then publish our files and setting\n<pre class=\"lang:default decode:true\">teddy@teddy-K43SJ:~\/Documents\/works\/laravel\/latihan-crud$ php artisan vendor:publish\r\nCopied Directory [\/vendor\/laravel\/framework\/src\/Illuminate\/Notifications\/resources\/views] To [\/resources\/views\/vendor\/notifications]\r\nCopied Directory [\/vendor\/laravel\/framework\/src\/Illuminate\/Pagination\/resources\/views] To [\/resources\/views\/vendor\/pagination]\r\nCopied File [\/vendor\/appzcoder\/crud-generator\/config\/crudgenerator.php] To [\/config\/crudgenerator.php]\r\nCopied File [\/vendor\/appzcoder\/crud-generator\/publish\/app.blade.php] To [\/resources\/views\/layouts\/app.blade.php]\r\nCopied Directory [\/vendor\/appzcoder\/crud-generator\/src\/stubs] To [\/resources\/crud-generator]\r\nPublishing complete for tag []!<\/pre>\n<\/li>\n<li>Create a new class &#8216;Posts&#8217; for our crud generator with two fields &#8216;title&#8217; and<br \/>\n&lt;OLD&gt;<\/p>\n<pre class=\"lang:default decode:true \">php artisan crud:generate Posts --fields=\"title#string, body#text\"<\/pre>\n<p>BUT I GOT THIS ERROR:<\/p>\n<pre class=\"lang:default decode:true \">teddy@teddy-K43SJ:~\/Documents\/works\/laravel\/latihan-crud$ php artisan crud:generate Posts --fields=\"title#string, body#text\"\r\nController created successfully.\r\nModel created successfully.\r\nMigration created successfully.\r\n\r\n                                 \r\n  [ErrorException]               \r\n  Undefined index: string, body<\/pre>\n<p>&lt;\/OLD<br \/>\n&lt;NEW&gt;<br \/>\nFrom this <a href=\"https:\/\/packagist.org\/packages\/appzcoder\/crud-generator\" target=\"_blank\">https:\/\/packagist.org\/packages\/appzcoder\/crud-generator<\/a>, I found the source of the error, I supposed to use &#8216;;&#8217; (&#8220;title#string; body#text&#8221;) instead of &#8216;,&#8217; (&#8220;title#string, body#text&#8221;) between the fields like this (DONT USE THIS COMMAND. THIS IS ONLY JUST A CORRECT COMMAND)<\/p>\n<pre class=\"lang:default decode:true \">teddy@teddy-K43SJ:~\/Documents\/works\/laravel\/latihan-crud$ php artisan crud:generate Posts --fields=\"title#string; content#text; category#select#options=technology,tips,health\" --view-path=admin --controller-namespace=Admin --route-group=admin\r\nController created successfully.\r\nModel already exists!\r\nMigration created successfully.\r\nView created successfully.\r\nCrud\/Resource route added to \/home\/teddy\/Documents\/works\/laravel\/latihan-crud\/routes\/web.php<\/pre>\n<p>USE THIS COMMAND INSTEAD TO MAKE IT CONSISTENT WITH THE ORIGINAL TUTORIAL:<\/p>\n<pre class=\"lang:default decode:true \">teddy@teddy-K43SJ:~\/Documents\/works\/laravel\/latihan-crud$ php artisan crud:generate Posts --fields=\"title#string; body#text\"\r\nController already exists!\r\nModel already exists!\r\nMigration created successfully.\r\nView created successfully.\r\nCrud\/Resource route added to \/home\/teddy\/Documents\/works\/laravel\/latihan-crud\/routes\/web.php\r\n<\/pre>\n<p>&lt;\/NEW&gt;<br \/>\nThe script for the table migration would be exist in \/database\/migrations\/ directory (IF YOU FIND MORE THAN ONE SCRIPT WITH SAME TABLE &#8216;Posts&#8217; LIKE &#8216;2016_10_22_081014_create_posts_table.php&#8217; AND &#8216;2016_10_22_074719_create_posts_table.php&#8217;, PLS REMOVE THE OLD ONE FIRST! OR WE&#8217;D GET THIS ERROR: &#8220;Cannot declare class CreatePostsTable, because the name is already in use&#8221;)<\/p>\n<pre class=\"lang:default decode:true \">teddy@teddy-K43SJ:~\/Documents\/works\/laravel\/latihan-crud$ php artisan migrate\r\nMigration table created successfully.\r\nPHP Fatal error:  Cannot declare class CreatePostsTable, because the name is already in use in \/home\/teddy\/Documents\/works\/laravel\/latihan-crud\/database\/migrations\/2016_10_22_075907_create_posts_table.php on line 33\r\n\r\n                                                                             \r\n  [Symfony\\Component\\Debug\\Exception\\FatalErrorException]                    \r\n  Cannot declare class CreatePostsTable, because the name is already in use<\/pre>\n<\/li>\n<li>Push the table script to our database with &#8216;php artisan migrate&#8217;\n<pre class=\"lang:default decode:true \">teddy@teddy-K43SJ:~\/Documents\/works\/laravel\/latihan-crud$ php artisan migrateMigrated: 2014_10_12_000000_create_users_table\r\nMigrated: 2014_10_12_100000_create_password_resets_table\r\nMigrated: 2016_10_22_081014_create_posts_table<\/pre>\n<p>Check our database to make sure the new table &#8216;posts&#8217; is already created! SOMEHOW THE OTHERS TABLES &#8216;migrations&#8217;, &#8216;users&#8217; AND &#8216;password_resets&#8217; ARE CREATED ALSO!<\/li>\n<li>Test on the browser. Start the server: &#8216;php artisan serve&#8217; then open on our browser : http:\/\/localhost:8000\/ &#8211;&gt; It shows the laravel welcome page!<br \/>\nRemember, A new route &#8216;posts&#8217; is already created automatically from previous step, so to see the CRUD in action, pls go to http:\/\/localhost:8000\/posts<a href=\"http:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/posts.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-811\" src=\"http:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/posts-1024x256.jpg\" alt=\"posts\" width=\"840\" height=\"210\" srcset=\"https:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/posts-1024x256.jpg 1024w, https:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/posts-300x75.jpg 300w, https:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/posts-768x192.jpg 768w, https:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/posts.jpg 1190w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><\/li>\n<li>Add new data.<br \/>\nClick the &#8216;+&#8217; blue icon <a href=\"http:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/create-new.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-815\" src=\"http:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/create-new.png\" alt=\"create-new\" width=\"601\" height=\"226\" srcset=\"https:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/create-new.png 601w, https:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/create-new-300x113.png 300w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/a>then fill the form with the fields &#8216;Title&#8217; and &#8216;Body&#8217;. Then press &#8216;Create&#8217; Button<a href=\"http:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/new-post.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-813\" src=\"http:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/new-post.png\" alt=\"new-post\" width=\"767\" height=\"416\" srcset=\"https:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/new-post.png 767w, https:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/new-post-300x163.png 300w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/a>But I got this error:<\/p>\n<pre class=\"lang:default decode:true\">SQLSTATE[HY000]: General error: 1364 Field 'body' doesn't have a default value (SQL: insert into `posts` (`title`, `updated_at`, `created_at`) values (Title 1, 2016-10-22 09:27:24, 2016-10-22 09:27:24))<\/pre>\n<p>I found the solution! In &#8216;Post&#8217; class in \/app\/Post.php, at &#8216;$fillable&#8217; variable, It&#8217;s only has &#8216;title&#8217; field But there is no &#8216;body&#8217; field!<\/p>\n<pre class=\"lang:default decode:true \">class Post extends Model\r\n{\r\n    ...\r\n\r\n    \/**\r\n     * Attributes that should be mass-assignable.\r\n     *\r\n     * @var array\r\n     *\/\r\n    protected $fillable = ['title'];\r\n\r\n    \r\n}<\/pre>\n<p>So add &#8216;body&#8217; field like this:<\/p>\n<pre class=\"lang:default decode:true \">class Post extends Model\r\n{\r\n    ...\r\n\r\n    \/**\r\n     * Attributes that should be mass-assignable.\r\n     *\r\n     * @var array\r\n     *\/\r\n    protected $fillable = ['title','body'];\r\n    \r\n}<\/pre>\n<p>Then repeat the creation of new data! Here is the expected result<a href=\"http:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/posts.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-814\" src=\"http:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/posts.png\" alt=\"posts\" width=\"767\" height=\"226\" srcset=\"https:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/posts.png 767w, https:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/posts-300x88.png 300w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/a><a href=\"https:\/\/gilacoding.com\/read\/membuat-login-laravel-5-2-dengan-username-dan-hak-akses\" target=\"_blank\">Membuat Login Laravel 5 2 dengan username dan Hak akses<\/a><\/li>\n<li>At the right top of the page, there are two links &#8216;login&#8217; and &#8216;register&#8217; but none of them are working. To make them work, we need to create the authentication to create users like this: php artisan make:auth\n<pre class=\"lang:default decode:true \">teddy@teddy-K43SJ:~\/Documents\/works\/laravel\/latihan-crud$ php artisan make:auth\r\nAuthentication scaffolding generated successfully.\r\n<\/pre>\n<p>Dont forget to stop the server first by clicking CTRL+C!<br \/>\nThe above command would create some views for login, register, password, etc. Please check them in \/resources\/views\/auth\/ directory!<br \/>\nThis also create automatically a few new routes in \/routes\/web.php<\/p>\n<pre class=\"lang:default decode:true \">...\r\nAuth::routes();\r\n\r\nRoute::get('\/home', 'HomeController@index');<\/pre>\n<\/li>\n<li>Now we can try them on our browser<br \/>\nRemember, we dont need to create\/migrate the user table because we already did this at the previous step (#11) when we did the first migration!<br \/>\nNow the links &#8216;login&#8217; and &#8216;register&#8217; are working!<br \/>\nHere is the register page: http:\/\/localhost:8000\/register<a href=\"http:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/register.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-817\" src=\"http:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/register.png\" alt=\"register\" width=\"696\" height=\"343\" srcset=\"https:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/register.png 696w, https:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/register-300x148.png 300w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/a>I use password: satria. Successful registration would be redirected to http:\/\/localhost:8000\/home<a href=\"http:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/logged-in.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-818\" src=\"http:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/logged-in.png\" alt=\"logged-in\" width=\"995\" height=\"180\" srcset=\"https:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/logged-in.png 995w, https:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/logged-in-300x54.png 300w, https:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2016\/10\/logged-in-768x139.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a>The links &#8216;login&#8217; and &#8216;register&#8217; also be showed up on the initial page http:\/\/localhost:8000\/<\/li>\n<li>Change\/set default route &#8216;\/&#8217;<br \/>\nIn \/routes\/web.php, the default route for http:\/\/localhost:8000\/ would go to the welcome page in \/resources\/views\/welcome.blade.php. Here is the default route<\/p>\n<pre class=\"lang:default decode:true \">Route::get('\/', function () {\r\n    return view('welcome');\r\n});<\/pre>\n<p>We want to change it to go to our login page! We have the login page in \/resources\/views\/auth\/login.blade.php. So here is the modified route<\/p>\n<pre class=\"lang:default decode:true \">Route::get('\/', function () {\r\n    \/\/return view('welcome');\r\n    return view('auth\/login');\r\n    \/\/return redirect()-&gt;route('posts');\r\n});<\/pre>\n<p>Now each our homepage http:\/\/localhost:8000\/ is opened, it&#8217;d open the login page!<br \/>\nIf we want to set the default route to the post page, please modify \/routes\/web.php like this:<\/p>\n<pre class=\"lang:default decode:true \">Route::get('\/', 'PostsController@index');<\/pre>\n<p>Now, if we open http:\/\/localhost:8000\/, it&#8217;d show the list of the post page!<br \/>\nLEARN ALSO THIS:<br \/>\n<a href=\"https:\/\/github.com\/appzcoder\/laravel-admin\" target=\"_blank\">Laravel Admin Panel<\/a><br \/>\nAn admin panel for managing users, roles, permissions &amp; crud.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/gilacoding.com\/read\/membuat-crud-laravel-hanya-dengan-5-menit Create a new laravel project named &#8216;latihan-crud&#8217; Type this command: composer create-project &#8211;prefer-dist laravel\/laravel latihan-crud teddy@teddy-K43SJ:~\/Documents\/works\/laravel$ composer create-project &#8211;prefer-dist laravel\/laravel latihan-crud Warning: This development build of composer is over 60 days old. It is recommended to update it by running &#8220;\/usr\/local\/bin\/composer self-update&#8221; to get the latest version. Installing laravel\/laravel (v5.3.16) &#8211; Installing laravel\/laravel &hellip; <a href=\"https:\/\/myprojects.advchaweb.com\/index.php\/2016\/10\/22\/fast-crud-with-laravel-5\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Fast CRUD With Laravel 5&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,13],"tags":[],"class_list":["post-799","post","type-post","status-publish","format-standard","hentry","category-laravel","category-tutorial"],"_links":{"self":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts\/799","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/comments?post=799"}],"version-history":[{"count":18,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts\/799\/revisions"}],"predecessor-version":[{"id":801,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts\/799\/revisions\/801"}],"wp:attachment":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/media?parent=799"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/categories?post=799"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/tags?post=799"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}