Setting Database Di laravel
dan belajar laravel
D: -> laravel new Berita
composer create-project laravel/laravel Berita
cd berita -> start php artisan serve
cd C:/xampp/mysql/bin
mysql -u root
create database dbBerita;
show tables;
->.env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=dbBerita
DB_USERNAME=root
DB_PASSWORD=
=>cd/d D:->cd Berita
php artisan make:mode Berita -mr
public function up()
{
Schema::create('beritas', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->string('title');
$table->text('body');
$table->timestamps();
});
}
php artisan make:model Jawab -mc
app->providers->appserviceprovider.php
\Schema::defaultStringLength(191);
php artisan migrate
DROP TABLE migrations;
DROP TABLE users;
public function up()
{
Schema::create('jawabs', function (Blueprint $table) {
$table->increments('id');
$table->integer('berita_id');
$table->integer('user_id');
$table->text('body');
$table->timestamps();
});
}
factory here code
ctrl+p =>ModelFactory.php
$factory->define(App\Berita::class,function($faker){
return[
'user_id'=>function(){
return factory('App\User')->create()->id;
},
'title'=>$faker->sentence,
'body'=>$faker->paragraph
];
});
php artisan tinker
factory('App\Berita',10)->create();
$factory->define(App\Jawab::class,function($faker){
return[
'berita_id'=>function(){
return factory('App\Berita')->create()->id;
},
'user_id'=>function(){
return factory('App\User')->create()->id;
},
'body'=>$faker->paragraph
];
});
factory('App\Jawab',10)->create();
$Beritas=factory('App\Berita',10)->create();
$Beritas->each(function($berita){factory('App\Jawab',10)->create(['berita_id'=>$berita->id]);});
dan belajar laravel
D: -> laravel new Berita
composer create-project laravel/laravel Berita
cd berita -> start php artisan serve
cd C:/xampp/mysql/bin
mysql -u root
create database dbBerita;
show tables;
->.env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=dbBerita
DB_USERNAME=root
DB_PASSWORD=
=>cd/d D:->cd Berita
php artisan make:mode Berita -mr
public function up()
{
Schema::create('beritas', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->string('title');
$table->text('body');
$table->timestamps();
});
}
php artisan make:model Jawab -mc
app->providers->appserviceprovider.php
\Schema::defaultStringLength(191);
php artisan migrate
DROP TABLE migrations;
DROP TABLE users;
public function up()
{
Schema::create('jawabs', function (Blueprint $table) {
$table->increments('id');
$table->integer('berita_id');
$table->integer('user_id');
$table->text('body');
$table->timestamps();
});
}
factory here code
ctrl+p =>ModelFactory.php
$factory->define(App\Berita::class,function($faker){
return[
'user_id'=>function(){
return factory('App\User')->create()->id;
},
'title'=>$faker->sentence,
'body'=>$faker->paragraph
];
});
php artisan tinker
factory('App\Berita',10)->create();
$factory->define(App\Jawab::class,function($faker){
return[
'berita_id'=>function(){
return factory('App\Berita')->create()->id;
},
'user_id'=>function(){
return factory('App\User')->create()->id;
},
'body'=>$faker->paragraph
];
});
factory('App\Jawab',10)->create();
$Beritas=factory('App\Berita',10)->create();
$Beritas->each(function($berita){factory('App\Jawab',10)->create(['berita_id'=>$berita->id]);});