本文整理汇总了PHP中app\Language::firstOrCreate方法的典型用法代码示例。如果您正苦于以下问题:PHP Language::firstOrCreate方法的具体用法?PHP Language::firstOrCreate怎么用?PHP Language::firstOrCreate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Language
的用法示例。
在下文中一共展示了Language::firstOrCreate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id, Request $request)
{
$book = \App\Book::findOrFail($id);
// $book->update(\Input::all());
// return \Redirect::back()->with('message','Book updated.');
// if($book){
// $rules = \App\Book::$rules;
//$rules['name'] = 'required|min:2';
// $validator = \Validator::make(\Input::all(), $rules);
// if($validator->passes())
// {
$book->description = $request->description;
$book->publisher_id = \App\Publisher::firstOrCreate(['name' => ucfirst($request->publisher)])->id;
$book->category_id = \App\Category::firstOrCreate(['name' => ucfirst($request->category)])->id;
$book->language_id = \App\Language::firstOrCreate(['name' => ucfirst($request->language)])->id;
$book->release_date = $request->release_date;
$book->save();
//going over author names build up array of author ids by getting author ids and creating author if does not exist
$authorIds = [];
$authors = $request->authors;
if ($authors) {
foreach ($authors as $author) {
$authorIds[] = App\Author::firstOrCreate(['name' => ucfirst($author)])->id;
}
//atached book to authors
$book->authors()->sync($authorIds);
// $book->authors()->attach($authorIds);
}
if ($request->hasFile('image')) {
$this->setBookImage($book, $request);
}
flash('Book updated.');
return \Redirect::back();
// }
// return \Redirect::back()
// //->with('message','There were some errors. Please try again later..')
// ->withInput()
// ->withErrors($validator);
// }
//
// flash()->error('Book does not exist.');
// return \Redirect::back();
}