Skip to content

Instantly share code, notes, and snippets.

@index0h
Created November 27, 2015 17:46
app/models/Photo.php
<?php
namespace app\models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use KoKoKo\Assert\Assert;
class Photo extends Model
{
/** @var int */
private $id;
/** @var string */
private $title;
/** @var string */
private $description;
/** @var int */
private $order;
/** @var int */
private $albumId;
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
* @return $this
* @throws \InvalidArgumentException
*/
public function setId($id)
{
Assert::assert($id, 'id')->int()->positive();
$this->id = $id;
return $this;
}
/**
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* @param string $title
* @return $this
* @throws \InvalidArgumentException
*/
public function setTitle($title)
{
Assert::assert($title, 'title')->notEmpty()->string();
$this->title = $title;
return $this;
}
/**
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* @param string $description
* @return $this
* @throws \InvalidArgumentException
*/
public function setDescription($description)
{
Assert::assert($description, 'description')->notEmpty()->string();
$this->description = $description;
return $this;
}
/**
* @return int
*/
public function getOrder()
{
return $this->order;
}
/**
* @param int $order
* @return $this
* @throws \InvalidArgumentException
*/
public function setOrder($order)
{
Assert::assert($order, 'order')->int()->positive();
$this->order = $order;
return $this;
}
/**
* @return int
*/
public function getAlbumId()
{
return $this->albumId;
}
/**
* @param int $albumId
* @return $this
* @throws \InvalidArgumentException
*/
public function setAlbumId($albumId)
{
Assert::assert($albumId, 'albumId')->int()->positive();
$this->albumId = $albumId;
return $this;
}
/**
* @return string
*/
public function getTable()
{
return 'photos';
}
/**
* @return BelongsTo
*/
public function getAlbum()
{
return $this->belongsTo(Album::class);
}
/**
* @param array $attributes
* @return $this
*/
public function fill(array $attributes)
{
if (array_key_exists('id', $attributes)) {
$this->setId($attributes['id']);
}
if (array_key_exists('title', $attributes)) {
$this->setTitle($attributes['title']);
}
if (array_key_exists('description', $attributes)) {
$this->setDescription($attributes['description']);
}
if (array_key_exists('order', $attributes)) {
$this->setOrder($attributes['order']);
}
if (array_key_exists('albumId', $attributes)) {
$this->setAlbumId($attributes['albumId']);
}
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment