Skip to content

Instantly share code, notes, and snippets.

@bkawakami
Created August 26, 2015 23:08
Show Gist options
  • Save bkawakami/912f871f5754df9e8948 to your computer and use it in GitHub Desktop.
Save bkawakami/912f871f5754df9e8948 to your computer and use it in GitHub Desktop.
Products.php
<?php
namespace MyProject;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Validator;
class Products extends Model
{
use SoftDeletes;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'products';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'description',
'code'
];
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
public static function validation(array $data, $id = null){
$hydrateValidation= null;
if ($id) {
$hydrateValidation = ','.$id.',id,deleted_at,null';
} else {
$hydrateValidation = ',null,id,deleted_at,null';
}
return Validator::make($data, [
'name' => 'max:255',
'code' => 'required|unique:products,code'.$hydrateValidation,
'description' => 'max:4096'
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment