for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php namespace Bedard\Shop\Traits;
use Flash;
use Lang;
use October\Rain\Database\ModelException;
trait StartEndable
{
/**
* Boot the startendable trait for this model.
*
* @return void
*/
public static function bootStartEndable()
static::extend(function($model) {
$model->bindEvent('model.afterValidate', function() use ($model) {
$model->validateStartEndDates();
});
}
* Ensure the start and end dates are valid.
public function validateStartEndDates()
// Start date must be after the end date
if ($this->start_at !== null &&
start_at
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
$this->end_at !== null &&
end_at
$this->start_at >= $this->end_at) {
Flash::error(Lang::get('bedard.shop::lang.traits.startendable.start_at_invalid'));
throw new ModelException($this);
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: