2017-06-11 07:27:19 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Repositories;
|
|
|
|
|
|
|
|
use Illuminate\Validation\Validator;
|
|
|
|
|
2017-08-25 02:03:10 +08:00
|
|
|
|
|
|
|
abstract class BaseRepository extends \Prettus\Repository\Eloquent\BaseRepository {
|
2017-06-11 07:27:19 +08:00
|
|
|
|
2017-11-01 09:29:40 +08:00
|
|
|
public function findWithoutFail($id, $columns = ['*'])
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
return $this->find($id, $columns);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function validate($values)
|
|
|
|
{
|
2017-06-11 07:27:19 +08:00
|
|
|
$validator = Validator::make(
|
|
|
|
$values,
|
|
|
|
$this->model()->rules
|
|
|
|
);
|
|
|
|
|
|
|
|
if($validator->fails()) {
|
|
|
|
return $validator->messages();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|