public function run() { factory(App\User::class, 30)->create(); //->each(function($u) {}); factory(App\Task::class, 20)->create(); factory(App\Job::class, 3)->create(); $tasks = App\Task::all(); foreach ($tasks as $task) { $task->users()->sync($task->asignees); $task->task()->save($tasks->random()->first()->id); } }
| | Here you may define all of your model factories. Model factories give | you a convenient way to create models for testing and seeding your | database. Just tell the factory how a default model should look. | */ $factory->define(App\User::class, function (Faker\Generator $faker) { return ['username' => $faker->userName, 'name' => $faker->name, 'email' => $faker->email, 'password' => bcrypt(str_random(10)), 'remember_token' => str_random(10)]; }); $factory->define(App\Task::class, function (Faker\Generator $faker) { $users = App\User::all()->lists('id')->all(); return ['name' => $faker->realText(30), 'description' => $faker->realText(200), 'extra_info' => $faker->realText(200), 'date_expected' => $faker->dateTime('+ 1 month'), 'date_finished' => $faker->dateTime('+ 1 month'), 'duration_expected' => mt_rand(1, 16) * 15, 'duration_finished' => mt_rand(1, 16) * 15, 'done' => $faker->boolean(), 'status' => rand(0, 6), 'asignees' => $faker->randomElements($users, mt_rand(1, 11))]; }); $factory->define(App\Job::class, function (Faker\Generator $faker) { $users = App\User::all()->lists('id')->all(); $tasks = App\Task::all()->lists('id')->all(); $deliverables = array(); for ($i = 0; $i < mt_rand(2, 7); $i++) { array_push($deliverables, 1); } $sessions = array(); for ($i = 0; $i < mt_rand(2, 7); $i++) { array_push($sessions, 1); } $materials = array(); for ($i = 0; $i < mt_rand(2, 7); $i++) { array_push($materials, 1); } $payments = array(); for ($i = 0; $i < mt_rand(2, 7); $i++) { array_push($payments, 1);
| Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ Route::get('/', 'WelcomeController@index'); Route::get('dashboard', 'PagesController@dashboard'); Route::get('login', 'PagesController@login'); Route::get('home', function () { if (Auth::guest()) { return Redirect::to('login'); } else { return view('pages.dashboard')->with('users', App\User::all())->with('task_categories', App\TaskCategory::all())->with('tasks', App\Task::all())->with('companies', App\Company::all())->with('contracts', App\Contract::all())->with('solutions', App\Solution::all())->with('clients', App\Client::all())->with('employees', App\Employee::all()); } }); // model routes.. Route::post('tc/store', 'TaskCategoryController@store'); Route::post('tc/edit/{id}', array('uses' => 'TaskCategoryController@edit', 'as' => 'route.edit')); Route::patch('tc/{id}', array('uses' => 'TaskCategoryController@update', 'as' => 'route.update')); Route::delete('tc/{id}', array('uses' => 'TaskCategoryController@destroy', 'as' => 'route.destroy')); Route::post('task/store', 'TaskController@store'); Route::post('task/edit/{id}', array('uses' => 'TaskController@edit', 'as' => 'task.edit')); Route::post('task/approve/{id}', array('uses' => 'TaskController@approve', 'as' => 'task.approve')); Route::patch('task/{id}', array('uses' => 'TaskController@update', 'as' => 'task.update')); Route::delete('task/{id}', array('uses' => 'TaskController@destroy', 'as' => 'task.destroy')); Route::post('client/store', 'ClientController@store'); Route::post('client/edit/{id}', array('uses' => 'ClientController@edit', 'as' => 'client.edit')); Route::patch('client/{id}', array('uses' => 'ClientController@update', 'as' => 'client.update'));