我正在创建一个带有日期字段的create post表单,而没有在表单中输入日期时,我创建了一个变数器以使数据库中的日期为NULL。
create.blade.php中的表格
#include <iostream>
int main()
{
while ( true )
{
std::cout << "Enter the Number You Want to Check (0 - exit): ";
unsigned int n;
if ( not ( std::cin >> n ) or ( n == 0 ) ) break;
unsigned int i = 2;
while ( ( i <= n / i ) and ( n % i != 0 ) ) i++;
if ( ( n == 1 ) or ( i <= n / i ) )
{
std::cout << "No, " << n << " is not prime.\n";
}
else
{
std::cout << "The number " << n << " is prime.\n";
}
}
return 0;
}
Post.php中的Mutator:
Enter the Number You Want to Check (0 - exit): 1
No, 1 is not prime.
Enter the Number You Want to Check (0 - exit): 2
The number 2 is prime.
Enter the Number You Want to Check (0 - exit): 3
The number 3 is prime.
Enter the Number You Want to Check (0 - exit): 4
No, 4 is not prime.
Enter the Number You Want to Check (0 - exit): 5
The number 5 is prime.
Enter the Number You Want to Check (0 - exit): 6
No, 6 is not prime.
Enter the Number You Want to Check (0 - exit): 7
The number 7 is prime.
Enter the Number You Want to Check (0 - exit): 8
No, 8 is not prime.
Enter the Number You Want to Check (0 - exit): 9
No, 9 is not prime.
Enter the Number You Want to Check (0 - exit): 10
No, 10 is not prime.
Enter the Number You Want to Check (0 - exit): 0
在控制器中存储功能:
#include <iostream>
int main()
{
while ( true )
{
std::cout << "Enter the Number You Want to Check (0 - exit): ";
unsigned int n;
if ( not ( std::cin >> n ) or ( n == 0 ) ) break;
bool prime = n % 2 == 0 ? n == 2 : n != 1;
for ( unsigned int i = 3; prime and i <= n / i; i += 2 )
{
prime = n % i;
}
if ( prime )
{
std::cout << "The number " << n << " is prime.\n";
}
else
{
std::cout << "No, " << n << " is not prime.\n";
}
}
return 0;
}
我期望在数据库中不输入日期时该日期为NULL,但是在“在处发布的格式与Y-m-d H:i:s格式不匹配”时出现验证错误。而且不会提交
答案 0 :(得分:0)
只需进行验证published_at=>'sometimes|date_format:Y-m-d H:i:s'
答案 1 :(得分:0)
您可以执行以下操作
'published_at' => 'nullable|date_format:Y-m-d H:i:s',
以及您的迁移文件 您可以将属性设置为可空
$table->timestamp('published_at')->nullable();
因此,如果没有值,则可以为空