I am working on REST API with add/update/delete methods.
In Controller, In Update action i have to check if id passed exists, I know i can use Laravel validator exists:table,column , but i am using Repository inside controller
public function __construct(BookRepositoryInterface $bookRepository, Validator $validator)
{
$this->bookRepository = $bookRepository;
$this->validator = $validator;
}
Repository source can be different than mysql database. Laravel validator 'exists' will not work in every case.
This is the code for updating book by an id.
public function update($id)
{
$params = Input::only('title', 'author');
$params['id'] = $id;
$rules = array(
'id' => 'required',
'author' => 'required',
'title' => 'required'
);
$validator = $this->validator->make($params, $rules);
...........
}
What is best way to check if id exists in book repository during update?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire