本文整理汇总了PHP中Books::insertGetId方法的典型用法代码示例。如果您正苦于以下问题:PHP Books::insertGetId方法的具体用法?PHP Books::insertGetId怎么用?PHP Books::insertGetId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Books
的用法示例。
在下文中一共展示了Books::insertGetId方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$books = (array) json_decode(Input::all()['add_book_data']);
DB::transaction(function () use($books) {
$db_flag = false;
$user_id = Auth::id();
$book_title = Books::insertGetId(array('title' => $books['title'], 'author' => $books['author'], 'description' => $books['description'], 'category_id' => $books['category'], 'added_by' => $user_id));
$newId = $book_title;
if (!$book_title) {
$db_flag = true;
} else {
$number_of_issues = $books['number'];
for ($i = 0; $i < $number_of_issues; $i++) {
$issues = Issue::create(array('book_id' => $newId, 'added_by' => $user_id));
if (!$issues) {
$db_flag = true;
}
}
}
if ($db_flag) {
throw new Exception('Invalid update data provided');
}
});
return "Books Added successfully to Database";
}