我知道这个问题之前已被多次询问,但没有人解释当你在模型中验证时如何获得id.
'email' => 'unique:users,email_address,10'
Run Code Online (Sandbox Code Playgroud)
我的验证规则在模型中,因此如何将记录的ID传递给验证规则.
这是我的模特/用户
protected $rules_update = [
'email_address' => 'required|email|unique:users,email_address,'.$id,
'first_name' => "required",
'last_name' => "required",
'password' => "required|min:6|same:password_confirm",
'password_confirm' => "required:min:6|same:password",
'password_current' => "required:min:6"
];
Run Code Online (Sandbox Code Playgroud)
车型/ BaseModel
protected $rules = array();
public $errors;
/*
* @data: array, Data to be validated
* @rules: string, rule name in model
*/
public function validate($data, $rules = "rules") {
$validation = Validator::make($data, $this->$rules);
if($validation->passes()) {
return true;
}
$this->errors = $validation->messages();
return false;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试开发REST API Web服务.我有一个关于如何处理用户激活电子邮件的问题.目前,API服务处理电子邮件发送.
这是我目前的流程:
这是我目前看到的问题:
由于API服务当前正在发送电子邮件,因此客户端应用程序无法控制电子邮件的外观.并且电子邮件中可能存在应指向客户端应用程序的URL.
另一个选项是发送激活电子邮件的API服务,它将激活密钥返回给客户端应用程序.然后,客户端应用程序将能够将激活电子邮件发送给用户.
我在这个策略中看到两个问题:
你认为最好的办法是什么?
我想允许客户端应用程序自定义他们的电子邮件,以及包含客户端特定的URL(激活页面).
Laravel中的验证类是否验证了确切的单词?
例如
$rules = [
"field" => "hello"
]
Run Code Online (Sandbox Code Playgroud)
该字段的值必须是"你好".
我正在domain.com?para=value使用控制器中的URL 中的
参数获取值Input:all()
有没有办法Input:all()在控制器中添加更多值?
我曾尝试$_POST['para'] = "value和$_GET['para'] = "value",但没有运气.
我已经浏览了文档但却找不到任何内容.
谢谢
更多信息
这是返回的内容
{
"param_1" => "value",
"param_2" => "value",
"param_3" => "value",
}
Run Code Online (Sandbox Code Playgroud)
我想在其中添加另一个参数 Input:all()
{
"param_1" => "value",
"param_2" => "value",
"param_3" => "value",
"NEW_PARAM" => "NEW VALUE",
}
Run Code Online (Sandbox Code Playgroud) 是否还有其他人在通过 Composer 安装 gedmo/doctrine-extensions 时遇到问题?
存储库是公开的,所以我不确定为什么说它是私有存储库
Cloning failed using an ssh key for authentication, enter your GitHub credentials to access private repos
Head to https://github.com/settings/tokens/new?scopes=repo&description=Composer+on+computername+2015-09-04+1040
to retrieve a token. It will be stored in "/location/.composer/auth.json" for future use by Composer.
Token (hidden):
我正在开发Laravel和Backbone系统.
用户可以查看他们自己的简档,例如,电子邮件地址,姓名,DOB等
在Laravel我使用资源控制器(索引,创建,存储,显示,编辑,更新和销毁)
因此,如果用户想要查看他们自己的个人资料,他们会访问domain.com/users/{their ID}.
我遇到的问题是如何将{他们的ID}传递给骨干网,以便我可以将其附加到域名,因此当骨干网获取时,它可以获取他们的记录.
Backbone工作正常.如果我在其中硬编码id将获取正确的数据.
用户ID当前存储在会话中.
这里的最佳做法是什么?您认为如何发送骨干用户ID.
Backbone Model/profile.js
var Profile = Backbone.Model.extend({
urlRoot: domain + "/users",
initialize: function () {
this.profile = new ProfileCollection();
}
}),
ProfileCollection = Backbone.Collection.extend({
initialize: function(models, options = {}) {
this.id = options.id;
},
url: function() {
return domain + "/users/" + this.id;
},
model: Profile,
});
return {
Profile: Profile,
ProfileCollection: ProfileCollection
}
Run Code Online (Sandbox Code Playgroud)
Backbone View/profile.js
var ProfileView = Backbone.View.extend({
el: '.page',
initialize: function() {
self = this;
profile = new Profile.Profile; …Run Code Online (Sandbox Code Playgroud) 我正在使用dustin10/VichUploaderBundle上传图片.
我正在使用Gregwar/ImageBundle来调整图像大小.
dustin10/VichUploaderBundle有一个POST_UPLOAD事件.如何触发事件.我已经阅读了文档,但它没有说明如何触发事件.
https://github.com/dustin10/VichUploaderBundle/blob/master/Event/Events.php
计划是使用Post Upload上的ImageBundle调整图像大小.
小号
有没有办法使用复选框表单类型与已设置为字符串的字段?
此字段可以包含许多值,可用于将数据作为文本字段或复选框输入.
我在formtype上有一个事件监听器来检查它是否应该是一个复选框或文本字段.
/Entity.php
/**
* @var string
*
* @ORM\Column(name="value", type="string", length=200, nullable=true)
*/
private $value;
Run Code Online (Sandbox Code Playgroud)
formtype.php
$form->add('value', 'checkbox', array(
))
Run Code Online (Sandbox Code Playgroud)
错误
Unable to transform value for property path "value": Expected a Boolean.
Run Code Online (Sandbox Code Playgroud) 我正在尝试获取所有数组元素,其中值仅在数组中出现一次.
我试着用:
array_unique($array);
Run Code Online (Sandbox Code Playgroud)
但这只会删除重复项,这不是我想要的.
举个例子:
$array = 0 => 1
1 => 2
2 => 3
3 => 4
4 => 5
5 => 2
6 => 3
7 => 4
8 => 5
Run Code Online (Sandbox Code Playgroud)
预期产量:
array(
0=>1
)
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,只有值1在数组中出现一次,所有其他值在数组中不止一次.所以我只想保留那一个元素.
有没有一种方法可以检查控制器内是否存在表单字段?
我有一些提交按钮,但是根据对象中的数据,将显示和创建关联的按钮。
FormType.php
$builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) {
/** @var ObjectInfo $tab */
$tab = $event->getData();
$form = $event->getForm();
if (some condition) {
//No Value has been set or NULL
$form->add('submit_second', 'submit', array(
'label' => 'submit',
))
}
Run Code Online (Sandbox Code Playgroud)
controller.php
if ($overviewForm->get('submit_second')->isClicked()) {
// do something
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过
if (
!is_null($overviewForm->get('submit_second')) &&
$overviewForm->get('submit_second')->isClicked()
) {
Run Code Online (Sandbox Code Playgroud)
提交后我得到
错误
Child "submit_second" does not exist.
Run Code Online (Sandbox Code Playgroud) laravel ×3
php ×3
symfony ×3
forms ×2
laravel-4 ×2
validation ×2
activation ×1
api ×1
arrays ×1
backbone.js ×1
composer-php ×1
events ×1
github ×1
rest ×1