내가 Laravel 5.2을 사용하고 있습니다를 사용하고, 문서로 말한다 없습니다부울 검증 laravel 5
부울
검증 아래의 필드가 부울로 캐스팅 할 수 있어야합니다. 허용되는 입력은 true, false, 1, 0, "1"및 "0"입니다.
따라서 checkbox (styled like a switch from materialize)을 만들었습니다. 켜져 있으면 true를 표시하고 꺼져 있으면 false를 반환합니다. 블레이드는 다음과 같습니다.
{!! Form::hidden('eh_capa', 0) !!}
Want to select as a graph cover?
<label>
Off
<input name="cover" type="checkbox" checked>
<span class="lever"></span>
on
</label>
물론이 코드는 양식 태그 안에 있습니다.
public function rules()
{
$this['cover'] = $this['cover'] === 'on' ? 1 : 0;
$this['obra_id'] = $this->route('obra');
$this['arquivo'] = $this->hasFile('arquivo') ? $this->file('arquivo') : NULL;
dd($this);
return [
'cover' => 'required|boolean',
'obra_id' => 'exists:obras',
'path' => 'required',
'arquivo' => 'required|file|max:2048|mimes:pdf',
];
}
DD 형식() 함수 내이 같은 요청을 반환합니다 :
StoreGraficoPostRequest {#441 ▼
#container: Application {#3 ▶}
#redirector: Redirector {#448 ▶}
#redirect: null
#redirectRoute: null
#redirectAction: null
#errorBag: "default"
#dontFlash: array:2 [▶]
#json: null
#convertedFiles: array:1 [▶]
#userResolver: Closure {#355 ▶}
#routeResolver: Closure {#354 ▶}
+attributes: ParameterBag {#443 ▶}
+request: ParameterBag {#440 ▼
#parameters: array:5 [▼
"_token" => "bZIpGW6UCcYHlCTZuIZMtmOrpCodWyfcbO1HgQid"
"path" => "hello.pdf"
"cover" => 1
"obra_id" => "29"
"arquivo" => UploadedFile {#438 ▶}
]
}
+query: ParameterBag {#442 ▶}
+server: ServerBag {#446 ▶}
+files: FileBag {#445 ▶}
+cookies: ParameterBag {#444 ▶}
+headers: HeaderBag {#447 ▶}
#content: ""
#languages: null
#charsets: null
#encodings: null
#acceptableContentTypes: null
#pathInfo: null
#requestUri: null
#baseUrl: null
#basePath: null
#method: "POST"
#format: null
#session: Store {#394 ▶}
#locale: null
#defaultLocale: "en"
}
그러나 때를 laravel 문서의 this part에 말했듯이 요청 클래스 내부의 유효성 검사를 수행 여기 내 규칙 방법 dd 함수에 주석을 달아라. 검증은 true 또는 false 여야한다는 것을 반환한다. 표지 필드의 값을 true로 변경하면 "1"과 "true"가 켜져도 마찬가지입니다. 나는 모든 웹에서 도움이되고 아무것도 얻지 못했습니다 ... 나는 이것이 Laravel 버그라고 생각하기 시작했습니다. ...
그것은 laravel 버그 아니다. 현재 프로젝트에서 laravel 5.2를 사용하여 부울 검증을 사용합니다. 유효성 검사 규칙 내에서 요청 값을 설정하는 이유가 있습니까? –
아니, 이유가 없었어 ... 나는 그들이 나의 요청에 나타나도록 강요하려고 노력했다. 그러나 나는 @ sameeranand1이 이것을하는 방법에 대한 내 견해를 바꾸 었다고 생각한다. –
@ThalesNathan'''$ this -> [ 'field']'''는 실제로 일종의 뮤 테이터를 얻습니다.이 값은 이렇게 바꿀 수 없습니다;) –