/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::create();
     # Kosongin isi tabel
     DB::table('anggota')->delete();
     DB::table('status')->delete();
     DB::table('tokoBuku')->delete();
     # Tambahkan data toko buku
     $tokoBuku = TokoBuku::create(array('nama' => 'Taman Bacaan', 'alamat' => 'Jl. Cikapundung no. 17', 'telp' => '022-3261723'));
     $this->command->info('Data Toko Buku telah diisi!');
     #Faker
     $fake1 = Anggota::create(array('nama' => $faker->name, 'id_tokoBuku' => $tokoBuku->id));
     $fake2 = Anggota::create(array('nama' => $faker->name, 'id_tokoBuku' => $tokoBuku->id));
     $aulia = Anggota::create(array('nama' => 'Aulia Marchita', 'email' => '*****@*****.**', 'id_tokoBuku' => $tokoBuku->id));
     $arvin = Anggota::create(array('nama' => 'Arvin Chs', 'email' => '*****@*****.**', 'id_tokoBuku' => $tokoBuku->id));
     $puji = Anggota::create(array('nama' => 'Puji Muharani', 'email' => '*****@*****.**', 'id_tokoBuku' => $tokoBuku->id));
     $this->command->info('Anggota telah diisi!');
     Status::create(array('pekerjaan' => 'Pelajar', 'id_anggota' => $aulia->id));
     Status::create(array('pekerjaan' => 'Mahasiswa', 'id_anggota' => $arvin->id));
     Status::create(array('pekerjaan' => 'Pegawai', 'id_anggota' => $puji->id));
     $this->command->info('Data anggota dan status telah diisi!');
     DB::table('buku')->delete();
     DB::table('anggota_buku')->delete();
     # Isi tabel buku
     $circa = Buku::create(array('judul' => 'Circa', 'penulis' => 'Sitta Karina'));
     $madah = Buku::create(array('judul' => 'Madah', 'penulis' => 'Risa Saraswati'));
     $nts = Buku::create(array('judul' => 'Nothing To Lose', 'penulis' => 'Alia Zalea'));
     $aulia->buku()->attach($circa->id);
     $arvin->buku()->attach($nts->id);
     $arvin->buku()->attach($madah->id);
     $puji->buku()->attach($circa->id);
     $this->command->info('Anggota beserta buku telah diisi!');
 }
Exemple #2
0
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
    return view('welcome');
});
Route::get('relasi-1', function () {
    $anggota = Anggota::where('email', '=', '*****@*****.**')->first();
    return $anggota->status->pekerjaan;
});
Route::get('relasi-2', function () {
    $anggota = Anggota::where('email', '=', '*****@*****.**')->first();
    return $anggota->tokoBuku->nama;
});
Route::get('relasi-3', function () {
    $tokoBuku = TokoBuku::where('nama', '=', 'Taman Bacaan')->first();
    foreach ($tokoBuku->anggota as $temp) {
        echo '<li>  Nama : ' . $temp->nama . '
					    ' . $temp->email . ' </li>';
    }
});
Route::get('relasi-4', function () {
    $aulia = Anggota::where('nama', '=', 'Aulia Marchita')->first();
    foreach ($aulia->buku as $temp) {
        echo '<li>' . $temp->judul . '</li>';
    }
});
Route::get('relasi-5', function () {
    $circa = Buku::where('judul', '=', 'Circa')->first();
    foreach ($circa->anggota as $temp) {
        echo '<li> Nama : ' . $temp->nama . ' <strong>' . $temp->email . '</strong></li>';