有没有办法使用 Laravel 的验证语法来验证外键?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29611807/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there any way to validate a foreign key using Laravel's Validation syntax?
提问by ReactingToAngularVues
Say I have an object
which relates to a mission
. Users can upload objects and say that it has a relationship with one of these missions. Is there anyway to check that the mission_id
that the user has selected for this object actually exists in this database using Laravel's Validation
class and rules?
假设我有一个object
与 a 相关的mission
. 用户可以上传对象并说它与这些任务之一有关。无论如何要mission_id
使用 Laravel 的Validation
类和规则来检查用户为此对象选择的对象是否确实存在于该数据库中?
This way, I can check that mission_id
is not only an integer, but also exists in the database.
这样,我可以检查它mission_id
不仅是一个整数,而且还存在于数据库中。
For example, I guess I'm looking for something like:
例如,我想我正在寻找类似的东西:
$rules = array(
'mission_id' => 'foreignKeyExistsInMissions|integer'
)
Where foreignKeyExistsInMissions
is the validation rule I'm looking for.
foreignKeyExistsInMissions
我正在寻找的验证规则在哪里。