public function run() { $faker = Faker::create(); foreach (range(1, 100) as $index) { $client = Client::create(['name' => $faker->company, 'about' => $faker->sentence(), 'location' => $faker->city . ' ' . $faker->state, 'industry_id' => $faker->numberBetween(1, 10), 'agency_id' => $faker->numberBetween(1, 10)]); $staff = ClientStaff::create(['name' => $faker->firstName . ' ' . $faker->lastName, 'email' => $faker->email, 'type' => 'hr', 'client_id' => $client->id, 'telephone' => $faker->randomNumber(6)]); } }
/** * Create Staff * @return \Illuminate\Http\JsonResponse */ public function create() { $success = false; if (\Input::has('client_id') && \Input::has('name')) { $staffData = \Input::all(); // TODO: save uploaded image :| $staff = ClientStaff::create($staffData); // Destination path for uplaoded files which is at /public/uploads $destinationPath = public_path() . '/uploads/img/'; // Handle profile Picture if (Input::hasFile('profile_pic_filename')) { $file = Input::file('profile_pic_filename'); $profile_pic_filename = str_random(6) . '_' . str_replace(' ', '_', $file->getClientOriginalName()); $uploadSuccess = $file->move($destinationPath, $profile_pic_filename); if ($uploadSuccess) { $staff->profile_pic_filename = $profile_pic_filename; $staff->save(); } } $success = $staff == true; } return \Response::json(['success' => $success, 'data' => $success ? $staff->getTransformed(new ClientStaffTransformer()) : null]); }
/** * Turn this item object into a generic array * * @return array */ public function transform(ClientStaff $staff) { return ['id' => $staff->id, 'name' => $staff->name, 'telephone' => $staff->telephone, 'email' => $staff->email, 'profile_pic_url' => $staff->present()->profile_pic_url, 'type' => $staff->type]; }