本文整理汇总了PHP中app\Book::fill方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::fill方法的具体用法?PHP Book::fill怎么用?PHP Book::fill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Book
的用法示例。
在下文中一共展示了Book::fill方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(BookRequest $request)
{
if (Input::file('cover')->isValid()) {
$file = Input::file('cover');
$destinationPath = 'images/cover';
$fileName = rand(11111, 99999) . '_' . $file->getClientOriginalName();
Input::file('cover')->move($destinationPath, $fileName);
$data = new Book();
$data->fill($request->all());
$data->cover = $fileName;
$data->save();
return Redirect('admin/books')->with('successMessage', 'Berhasil menambah buku.');
} else {
return Redirect()->back();
}
}
示例2: importBooks
public function importBooks()
{
$rules = array('csvfile' => 'required|mimes:csv,txt');
try {
$file = Input::file('csvfile');
if (is_null($file)) {
throw new Exception("File upload required");
}
Excel::load($file, function ($reader) {
$results = $reader->all();
foreach ($results as $row) {
$book = new Book();
# First row should be like "Title, Author"
$data = array('title' => $row->title, 'author' => $row->author);
$book->fill($data);
$book->save();
}
});
} catch (Exception $e) {
return Redirect::to('/')->with(['books' => Book::all(), 'errors' => $e->getMessage()]);
}
return Redirect::to('/')->with(['books' => Book::all()]);
//return Redirect::to('/')->with('csvdata', $results);
}
示例3: generate
public function generate($vendor_slug, $tour_slug, $schedule_id)
{
// -------------------------------------------------
// check vendor
// -------------------------------------------------
$vendor = Vendor::SlugIs($vendor_slug)->first();
if (!$vendor) {
App::abort(404);
}
// -------------------------------------------------
// check tour
// -------------------------------------------------
$tour = $vendor->tours()->slugIs($tour_slug)->first();
if (!$tour) {
App::abort(404);
}
// -------------------------------------------------
// schedule
// -------------------------------------------------
$schedule = $tour->schedules()->find($schedule_id);
if (!$schedule) {
App::abort(404);
}
// -------------------------------------------------
// generate voucher
// -------------------------------------------------
$book = Book::where('user_id', '=', Auth::id())->ofSchedule($schedule->id)->first();
if (!$book) {
$book = new Book();
$book->fill(['discount_currency' => $schedule->currency, 'discount' => $schedule->discount, 'discount_code' => str_random(6), 'user_id' => Auth::id(), 'schedule_id' => $schedule->id]);
if (!$book->save()) {
return redirect()->back()->withErrors($book->getErrors);
}
}
return redirect()->route('web.me.index');
}