engelsystem/src/Models/BaseModel.php

52 lines
1.1 KiB
PHP
Raw Normal View History

2018-08-31 01:55:05 +02:00
<?php
namespace Engelsystem\Models;
2018-09-15 17:24:59 +02:00
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
2018-08-31 01:55:05 +02:00
use Illuminate\Database\Eloquent\Model;
abstract class BaseModel extends Model
{
/** @var bool Disable timestamps by default because of "Datensparsamkeit" */
public $timestamps = false;
/**
2018-09-15 17:24:59 +02:00
* Create a new model
*
2018-08-31 01:55:05 +02:00
* @param array $attributes
* @return BaseModel
*/
public function create(array $attributes = [])
{
$instance = new static($attributes);
$instance->save();
return $instance;
}
2018-09-15 17:24:59 +02:00
/**
* Find a model by its primary key
*
* @param mixed $id
* @param array $columns
* @return Builder|Builder[]|Collection|static|null
2018-09-15 17:24:59 +02:00
*/
public static function find($id, $columns = ['*'])
{
return static::query()->find($id, $columns);
}
2018-09-25 17:29:15 +02:00
/**
* Find a model by its attributes or create a new one
*
* @param mixed $id
* @param array $columns
* @return static|Model
*/
public static function findOrNew($id, $columns = ['*'])
{
return static::query()->findOrNew($id, $columns);
}
2018-08-31 01:55:05 +02:00
}