/** * Edit a particular Work. * @param $id * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function edit($id) { $work = \App\Work::where(['id' => $id])->first(); $workVideos = $work->videos; $workTypes = \App\WorkType::all(); return view('admin.works.edit', ['work' => $work, 'workVideos' => $workVideos, 'workTypes' => $workTypes]); }
/** * Run the database seeds. * * @return void */ public function run() { $edition = array('First edition', 'Second edition', 'Third edition', 'Fourth edition', 'Fifth edition', 'Sixth edition', 'Seventh edition', 'Eighth edition', 'Ninth edition', 'Tenth edition'); $status = array('active', 'inactive'); $publishers = \App\Publisher::getByStatus(\App\Publisher::STATUS_ACTIVE)->get()->toArray(); $workTypes = \App\WorkType::all()->toArray(); for ($i = 0; $i < 50; $i++) { $work = new \App\Work(); $work->title = 'work name ' . $i; $work->publication_year = rand(2000, 2015); $work->edition = $edition[array_rand($edition)]; $work->price = 123.45; $work->isbn = '12345678910' . $i; $work->publisher_id = $publishers[array_rand($publishers)]['id']; $work->work_type_id = $workTypes[array_rand($workTypes)]['id']; $work->status = $status[array_rand($status)]; $work->save(); } }
/* |-------------------------------------------------------------------------- | Model Factories |-------------------------------------------------------------------------- | | 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 ['name' => $faker->name, 'email' => $faker->email, 'password' => bcrypt('default')]; }); $factory->define(App\Author::class, function (Faker\Generator $faker) { $status = array('active', 'inactive'); return ['name' => $faker->name, 'status' => $status[array_rand($status)]]; }); $factory->define(App\WorkType::class, function (Faker\Generator $faker) { return ['description' => $faker->word]; }); $factory->define(App\Publisher::class, function (Faker\Generator $faker) { $status = array('active', 'inactive'); return ['name' => $faker->name, 'status' => $status[array_rand($status)]]; }); $factory->define(App\Work::class, function (Faker\Generator $faker) { $edition = array('First edition', 'Second edition', 'Third edition', 'Fourth edition', 'Fifth edition', 'Sixth edition', 'Seventh edition', 'Eighth edition', 'Ninth edition', 'Tenth edition'); $status = array('active', 'inactive'); $publishers = \App\Publisher::getByStatus(\App\Publisher::STATUS_ACTIVE)->get()->toArray(); $workTypes = \App\WorkType::all()->toArray(); return ['title' => $faker->name, 'publication_year' => rand(2000, 2015), 'edition' => $edition[array_rand($edition)], 'price' => 102.15, 'isbn' => $faker->isbn13, 'publisher_id' => $publishers[array_rand($publishers)]['id'], 'work_type_id' => $workTypes[array_rand($workTypes)]['id'], 'status' => $status[array_rand($status)]]; });
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { if (Gate::denies('admin')) { abort(403); } $out = ['form_route' => ['route' => ['track.update', $id], 'method' => 'PUT', 'class' => 'form-horizontal'], 'artist_credit' => []]; $out['track'] = Track::findOrNew((int) $id); $out['genre'] = Genre::orderBy('id')->lists('name', 'id'); if (count(Request::old())) { $old = Request::old(); $out['release'] = Release::find($old['release_id']); if (isset($old['artist_credit']['id'])) { foreach ($old['artist_credit']['id'] as $n => $ac_id) { $artist = Artist::where('id', $ac_id)->firstOrFail(); if (count($artist)) { $out['artist_credit'][$n]['name'] = $artist->name; $out['artist_credit'][$n]['work_type_id'] = $old['artist_credit']['work'][$n]; $out['artist_credit'][$n]['join_phrase'] = $old['artist_credit']['join'][$n]; $out['artist_credit'][$n]['artist_id'] = $old['artist_credit']['id'][$n]; } } } } else { $out['release'] = $out['track']->release; $out['artist_credit'] = $out['track']->credit->credit_name; } $out['work_type'] = WorkType::all(); $out['genres_selected'] = []; foreach ($out['track']->genres as $row) { $out['genres_selected'][] = $row->id; } return view('tracks.form', $out); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $pages = \App\Page::all(); $workTypes = \App\WorkType::all(); return view('admin.index', ['pages' => $pages, 'workTypes' => $workTypes]); }
/** * Returns view for homepage with all required info. */ public function showHomePage() { $workTypes = \App\WorkType::all(); $pages = \App\Page::all(); }