Created
August 26, 2015 23:08
-
-
Save bkawakami/912f871f5754df9e8948 to your computer and use it in GitHub Desktop.
Products.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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