firstOrNew() public static method

Get the first record matching the attributes or instantiate it.
public static firstOrNew ( array $attributes ) : Model
$attributes array
return Illuminate\Database\Eloquent\Model
Ejemplo n.º 1
0
 /**
  * Update or Insert if not exists store_key
  *
  * @param $key
  * @param $value
  * @return bool
  */
 public static function storePut($key, $value)
 {
     $table = parent::firstOrNew(array(self::$storeColumn['key'] => $key));
     $table->{self::$storeColumn['key']} = $key;
     $table->{self::$storeColumn['value']} = $value;
     return $table->save();
 }
Ejemplo n.º 2
0
 /**
  * Overrided firstOrNew method of Model to trim data
  *
  * @return object
  */
 public static function firstOrNew(array $data = array())
 {
     $trimedData = self::trimData($data);
     return parent::firstOrNew($trimedData);
 }