/** * Run the database seeds. * * @return void */ public function run() { $status = array('active', 'inactive'); for ($i = 0; $i < 10; $i++) { $publisher = new \App\Publisher(); $publisher->name = 'publisher-' . $i; $publisher->status = $status[array_rand($status)]; $publisher->save(); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $validator = \Validator::make(\Input::all(), \App\Publisher::$rules); if ($validator->passes()) { $publisher = new \App\Publisher(); $publisher->name = \Input::get('name'); $publisher->save(); flash('Publisher added.'); return \Redirect::back(); } return \Redirect::back()->withInput()->withErrors($validator); }
<?php /*layout chung trong project *gom co header --banner --navigator body --sidebar --content footer */ $books = App\Book::select('title', 'isbn')->get(); $authors = App\Author::select('name')->get(); $publishers = App\Publisher::select('name')->get(); $data = array(); foreach ($books as $book) { array_push($data, $book->isbn); array_push($data, $book->title . ' - tên sách'); } foreach ($authors as $author) { array_push($data, $author->name . ' - tác giả'); } foreach ($publishers as $publisher) { array_push($data, $publisher->name . ' - nhà xuất bản'); } echo "<script>var availableTags = " . json_encode($data) . ";</script>"; ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8">