/** * Run the database seeds. * * @return void */ public function run() { App\Models\Question::truncate(); $users = App\Models\User::all(); factory('App\\Models\\Question', 200)->create()->each(function ($question) use($users) { $question->user()->associate($users->random())->save(); }); }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('subscribes')->truncate(); $list = collect()->merge(App\Models\Question::all())->merge(App\Models\Tag::all()); $users = App\Models\User::all(); $list->each(function ($item) use($users) { for ($i = 0, $count = rand(0, 10); $i < $count; $i++) { $item->subscribers()->attach($users->random()); } }); }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('question_tags')->truncate(); $tags = App\Models\Tag::get(); App\Models\Question::get()->each(function ($question) use($tags) { $random_tags = $tags->random($count = rand(1, 5)); $random_tags = $count == 1 ? [$random_tags] : $random_tags->all(); foreach ($random_tags as $tag) { $question->tags()->attach($tag->id); } }); }
/** * Run the database seeds. * * @return void */ public function run() { App\Models\Answer::truncate(); $users = App\Models\User::all(); App\Models\Question::all()->each(function ($question) use($users) { for ($i = 0, $count = rand(0, 5); $i < $count; $i++) { $question->answers()->save($answer = factory('App\\Models\\Answer')->create()); $question->update(['is_resolved' => $answer->is_solution]); $answer->user()->associate($users->random())->save(); } }); }
/** * Run the database seeds. * * @return void */ public function run() { App\Models\Comment::truncate(); $list = collect()->merge(App\Models\Question::all())->merge(App\Models\Answer::all()); $users = App\Models\User::all(); $list->each(function ($item) use($users) { for ($i = 0, $count = rand(0, 5); $i < $count; $i++) { $item->comments()->save($comment = factory('App\\Models\\Comment')->create()); $comment->user()->associate($users->random())->save(); } }); }
<?php // Model binding Route::model('quizzes', 'App\\Models\\Quiz'); Route::model('questions', 'App\\Models\\Question'); Route::model('options', 'App\\Models\\Option'); Route::model('students', 'App\\Models\\Student'); Route::model('user', 'App\\Models\\User'); Route::bind('quizzes', function ($value, $route) { return App\Models\Quiz::whereId($value)->first(); }); Route::bind('questions', function ($value, $route) { return App\Models\Question::whereId($value)->first(); }); Route::bind('options', function ($value, $route) { return App\Models\Option::whereId($value)->first(); }); Route::bind('students', function ($value, $route) { return App\Models\Student::whereId($value)->first(); }); Route::bind('users', function ($value, $route) { return App\Models\User::whereId($value)->first(); }); // Pages Routes Route::get('/', 'PageController@index'); Route::get('admin', ['as' => 'admin', 'uses' => 'PageController@admin', 'middleware' => 'admin']); Route::get('student', ['as' => 'student', 'uses' => 'PageController@student', 'middleware' => 'student']); // Authentication Routes... Route::post('auth/login', 'Auth\\AuthController@postLogin'); Route::get('auth/logout', 'Auth\\AuthController@getLogout'); // Registration Routes...