我正在尝试使用"language> {language}> validation.php"中的验证属性来替换正确读取名称的:属性名称(输入名称)(例如:first_name>名字).使用起来似乎很简单,但验证器没有显示"好名字".
我有这个:
'attributes' => array(
'first_name' => 'voornaam'
, 'first name' => 'voornaam'
, 'firstname' => 'voornaam'
);
Run Code Online (Sandbox Code Playgroud)
用于显示错误:
@if($errors->has())
<ul>
@foreach ($errors->all() as $error)
<li class="help-inline errorColor">{{ $error }}</li>
@endforeach
</ul>
@endif
Run Code Online (Sandbox Code Playgroud)
并在控制器中进行验证:
$validation = Validator::make($input, $rules, $messages);
Run Code Online (Sandbox Code Playgroud)
$ messages数组:
$messages = array(
'required' => ':attribute is verplicht.'
, 'email' => ':attribute is geen geldig e-mail adres.'
, 'min' => ':attribute moet minimaal :min karakters bevatten.'
, 'numeric' => ':attribute mag alleen cijfers bevatten.'
, 'url' => …Run Code Online (Sandbox Code Playgroud) 我很擅长在PHP中使用抽象类和接口.
我正在尝试启动一个抽象类的扩展,但它不起作用.这可能是我遇到的Laravel特定问题.
情况就是这样:
这是界面:
<?php namespace Collection\Services\Validation;
interface SomeInterface {
public function with(array $input);
public function passes();
public function errors();
}
Run Code Online (Sandbox Code Playgroud)
这是抽象类:
<?php namespace Collection\Services\Validation;
use Illuminate\Validation\Factory;
abstract class SomeClass implements SomeInterface {
protected $validator;
protected $data = array();
protected $errors = array();
protected $rules = array();
public function __construct(Factory $validator)
{
$this->validator = $validator;
}
public function with(array $data)
{
$this->data = $data;
return $this;
}
public function passes()
{
$validator = $this->validator->make($this->data, $this->rules);
if( …Run Code Online (Sandbox Code Playgroud) 我正在尝试在同一个Vagrant VM中运行我的API和我的客户端.在客户端我想使用Guzzle.当我尝试设置一个简单的测试时,我从curl得到以下错误:
Fatal error: Uncaught exception 'GuzzleHttp\Exception\RequestException' with message '[curl] (#6) See http://curl.haxx.se/libcurl/c/libcurl-errors.html for an explanation of cURL errors [url]
Run Code Online (Sandbox Code Playgroud)
当我使用Github网址时,一切正常.我敢肯定的一点是,我的网址中没有拼写错误.
我有客户端和API指向我的VM的IP地址,并且两者都运行良好.
我还遇到了一个主题,建议在php.ini中使用cacert.pem证书,我已经尝试过,但它没有用.
有谁知道如何解决这个问题?
在我的 Eloquent 集合中,我想添加一个名为“可编辑”的额外列。“可编辑”应该包含在我在某些模型上运行的每个查询中。“可编辑”根据原始查询显示为真或假。
因此,我有一个应该在模型上的每个查询中运行的查询。在我的收藏中添加一个额外的列。“可编辑”的值由原始查询确定。
做这个的最好方式是什么?
我想覆盖类中的method(isValidatable)Illuminate\Validation\Validator.我通过创建一个扩展Validator的类(在Illuminate之外)并且只覆盖该isValidatable方法来完成此操作.
我认为这将有效,除了我不确定如何为Validator类(或实际CustomLaravelValidator类)创建服务提供程序.我以前创建过服务提供程序,但似乎在Validator serviceprovider(Illuminate\Validation\ValidationServiceProvider)中有很多内容.因此,我不知道我的这个类的自定义服务提供程序应该是什么样子.
这是我的CustomLaravelValidator类:
<?php namespace API\Extensions\Core;
use Illuminate\Validation\Validator;
class CustomLaravelValidator extends Validator {
/**
* Determine if the attribute is validatable.
*
* @param string $rule
* @param string $attribute
* @param mixed $value
* @return bool
*/
protected function isValidatable($rule, $attribute, $value)
{
// Validate integers on empty strings as well
if($rule == 'IntStrict')
{
return true;
}
return $this->presentOrRuleIsImplicit($rule, $attribute, $value) &&
$this->passesOptionalCheck($attribute);
}
}
Run Code Online (Sandbox Code Playgroud)
这是Laravel的默认ValidationServiceProvider:
<?php …Run Code Online (Sandbox Code Playgroud)