/** * When editing or adding a new book, we need a select dropdown of authors to choose from * A select is easy to generate when you have a key=>value pair to work with * This method will generate a key=>value pair of author id => author name * * @return Array */ public static function getIdNamePair() { $authors = array(); $collection = Author::all(); foreach ($collection as $author) { $authors[$author->id] = $author->name; } return $authors; }
public function index() { $data = Author::all(['id', 'name']); if (Datatable::shouldHandle()) { return Datatable::collection($data)->showColumns('id', 'name')->addColumn('1', function ($model) { $html = '<a href="' . route('admin.authors.edit', $model->id) . '" class="btn btnn"> <i class="mdi-editor-mode-edit"></i> </a>'; return $html; })->addColumn('2', function ($model) { $html = Form::open(['route' => ['admin.authors.destroy', $model->id], 'method' => 'delete']); $html .= '<button class="btn btnn" type="submit"> <i class="mdi-action-delete"></i> </button>'; $html .= Form::close(); return $html; })->searchColumns('name')->orderColumns('name')->make(); } return View::make('authors.index')->withTitle('Penulis'); }
public function testFindWithHash() { $this->assertNotNull(Author::find(array('name' => 'Tito'))); $this->assertNotNull(Author::find('first', array('name' => 'Tito'))); $this->assertEquals(1, count(Author::find('all', array('name' => 'Tito')))); $this->assertEquals(1, count(Author::all(array('name' => 'Tito')))); }
public function test_find_with_hash() { $this->assert_not_null(Author::find(array('name' => 'Tito'))); $this->assert_not_null(Author::find('first', array('name' => 'Tito'))); $this->assert_equals(1, count(Author::find('all', array('name' => 'Tito')))); $this->assert_equals(1, count(Author::all(array('name' => 'Tito')))); }
public function showAuthors() { $data = Author::all(); $this->throwError($data); return Response::json($data); }
function index() { global $twig; $authors = new Author(); echo $twig->render('author_list.html', array('authors' => $authors->all())); }
public function editUser($id = null) { if (Input::has('submit')) { $id = Input::get('id'); $rules = array('password' => 'required', 'password2' => 'required|same:password', 'role' => 'required'); $validator = Validator::make(Input::all(), $rules); if ($validator->passes()) { $user = User::find($id); $user->password = Hash::make(Input::get('password')); $user->idauthor = Input::get('author'); $user->role = Input::get('role'); $user->save(); return Redirect::to('admin/eduser/' . $id)->with('sukses', 'Ubah data User berhasil!'); } else { return Redirect::to('admin/eduser/' . $id)->withErrors($validator)->withInput(); } } else { $user = User::find($id); $act = 'edit'; $tmp = Author::all(); $authors = array(); $authors[0] = '-- PILIH AUTHOR --'; foreach ($tmp as $value) { $authors[$value->id] = $value->authorname; } $role = array(1 => 'admin', 2 => 'contributor', 3 => 'viewer'); return View::make('admin.user', compact('user', 'act', 'authors', 'role')); } }
/** * Get all Authors * * return array {@type Author} * * @view authorView * */ public function index() { return Author::all(); }