Any help?
Sep 28, 2015
1
Level 10
L5.1 Validation and Testing RestAPI
I'm building an API where other websites can send Json and call my Controller store Method. For this case they use cURL. Thats is why I can't use FormRequests. (https://laracasts.com/discuss/channels/laravel/restful-api-call-validation-and-response)
So I have a validator object in my controller like:
private function validator($data)
{
return Validator::make($data, [
'order_id' => 'required|unique:orders',
'order_date' => 'required|date_format:"Y-m-d H:i:s"',
//...
]);
How can I use my validation in my tests/OrderTest.php ?
I need something simple like this:
public function testIsInvalidWithoutADate()
{
$order = factory(App\Order::class, 'noDate')->make();
$this->assertFalse($order->validate());
}
And what is the best practice for placing the Order rules. Should I place my rules in a static $rules variable in the order model? I don't want to list them in my OrderController validator.
Greets Krizz
Please or to participate in this conversation.