find() public static method

Find a model by its primary key.
public static find ( mixed $id, array $columns = [] ) : Model | Illuminate\Database\Eloquent\Collection | static[] | static | null
$id mixed
$columns array
return Illuminate\Database\Eloquent\Model | Illuminate\Database\Eloquent\Collection | static[] | static | null
コード例 #1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $input = \Input::all();
     $validation = \Validator::make($input, $this->getRules());
     if ($validation->passes()) {
         $record = $this->Model->find($id)->update($input);
         return \Redirect::route($this->routeName . 'show', $id);
     }
     return \Redirect::route($this->routeName . 'edit', $id)->withInput()->withErrors($validation);
 }
コード例 #2
0
 /**
  * Get a specific resource.
  *
  * @param integer $id
  *
  * @return Resource
  * @throws ModelNotFoundException
  */
 public function getById($id)
 {
     return $this->model->find($id);
 }
コード例 #3
0
 /**
  * Update an existing item
  * @param  int  This variable is primary key that wants to update
  * @return boolean
  */
 public function update($id)
 {
     $result = $this->model->find($id)->fill($this->getInput())->save();
     return $result;
 }