当前位置: 首页>>代码示例>>PHP>>正文


PHP Language::firstOrCreate方法代码示例

本文整理汇总了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();
 }
开发者ID:atindermann08,项目名称:readr,代码行数:49,代码来源:BookController.php


注:本文中的app\Language::firstOrCreate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。