Last active
February 22, 2016 05:50
-
-
Save Moccine/44d229be08d0e1398fc4 to your computer and use it in GitHub Desktop.
Boomarks an Users TableSeeder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Seeder; | |
class BookmarksTableSeeder extends Seeder | |
{ | |
/** | |
* Run the database seeds. | |
* | |
* @return void | |
*/ | |
public function run() | |
{ | |
factory('App\Bookmark'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Seeder; | |
class avatarsTableSeeder extends Seeder | |
{ | |
/** | |
* Run the database seeds. | |
* | |
* @return void | |
*/ | |
public function run() | |
{ | |
factory('App\Avatar'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Database\Migrations\Migration; | |
class CreateBookmarksTable extends Migration | |
{ | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
Schema::create('bookmarks', function (Blueprint $table) { | |
$table->increments('id'); | |
$table->integer('user_id')->unsigned(); | |
$table->string('user_username'); | |
$table->foreign('user_id')->references('id')->on('users'); | |
$table->foreign('user_username')->references('username')->on('users'); | |
$table->string('url_bm'); | |
$table->string('category'); | |
$table->timestamps(); | |
}); | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
Schema::drop('bookmarks'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Database\Migrations\Migration; | |
class CreatePasswordResetsTable extends Migration | |
{ | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
Schema::create('password_resets', function (Blueprint $table) { | |
$table->string('email')->index(); | |
$table->string('token')->index(); | |
$table->timestamp('created_at'); | |
}); | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
Schema::drop('password_resets'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Database\Migrations\Migration; | |
class CreateUsersTable extends Migration | |
{ | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
Schema::create('users', function (Blueprint $table) { | |
$table->increments('id'); | |
$table->string('username'); | |
$table->string('email')->unique(); | |
$table->string('password', 60); | |
$table->rememberToken(); | |
$table->timestamps(); | |
}); | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
Schema::drop('users'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Seeder; | |
use Illuminate\Support\Facades\DB; | |
class DatabaseSeeder extends Seeder | |
{ | |
/** | |
* Run the database seeds. | |
* | |
* @return void | |
*/ | |
public function run() | |
{ | |
// $this->call(UserTableSeeder::class); | |
factory(App\User::class, 20)->create()->each(function ($user) { | |
$user->avatars()->save(factory(App\Avatar::class) | |
->make([ | |
"user_id" => $user['id'] | |
])); | |
$loopLimit=rand(55, 100); // Permet de ne pas avoir un utlisateur sans url | |
for ($i =50; $i <=$loopLimit; $i++) { | |
$user->bookmarks()->save(factory(App\Bookmark::class) | |
->make([ | |
"user_username" => $user['username'], | |
"user_id" => $user['id'] | |
])); | |
} | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd My\Projet\Path | |
php artisan migrate | |
php artisan db:seed | |
// or php artisan mirgrate:refresh --seed --force | |
/*********** | |
*Option tinker | |
*/ | |
/*------------------------------ | |
php artisan tinker | |
factory(App\User,1)->make(); | |
factory(App\Bookmark,1)->make(); | |
factory(App\Avatar,1)->make(); | |
$myseed=new DatabaseSeeder(); | |
$myseed->run(); | |
-------------------------------*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Database\Migrations\Migration; | |
class CreateAvatarsTable extends Migration | |
{ | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
//DB::table('avatars')->truncate(); | |
Schema::create('avatars', function (Blueprint $table) { | |
$table->engine = 'InnoDB'; | |
$table->integer('user_id')->unsigned()->index(); | |
$table->foreign('user_id')->references('id')->on('users'); | |
$table->increments('id'); | |
$table->string('avatar')->unique(); | |
$table->timestamps(); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$factory->define(App\User::class, function (Faker\Generator $faker) { | |
return [ | |
'username' => $faker->userName, | |
'email' => $faker->email, | |
'password' => bcrypt(123654), | |
'remember_token' => str_random(10), | |
]; | |
}); | |
$factory->define(App\Bookmark::class, function (Faker\Generator $faker) { | |
$cat=App\Http\Utilities\BookmarkConst::$categories;// | |
$catN=rand(0,sizeof($cat)-1); | |
return [ | |
'user_username' => $faker->userName, | |
'url_bm' => $faker->url, | |
'category' => $cat[$catN], | |
'vue' => $faker->numberBetween(0,145) | |
]; | |
}); | |
$factory->define(App\Avatar::class, function (Faker\Generator $faker) { | |
return [ | |
"user_id" => $faker->numberBetween(1,1000), | |
'avatar' => $faker->imageUrl(150,150) | |
]; | |
}); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Illuminate\Database\Seeder; | |
class UsersTableSeeder extends Seeder | |
{ | |
/** | |
* Run the database seeds. | |
* | |
* @return void | |
*/ | |
public function run() | |
{ | |
factory('App\User'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment