[英]Laravel Blade Request method
最近,我通過關注Laravel From Scratch演員( https://laracasts.com/series/laravel-5-from-scratch )開始學習Laravel。
現在,我正在嘗試向注冊表單添加其他功能(從錯誤反饋開始),我已經遇到了問題。
是否有(本機)檢查表單是否已提交的方法? 我嘗試使用:
{{ Request::method() }}
但是,即使在通過運行命令php artisan make:auth
生成的默認支架上按了Register之后,它也將在表單的操作為POST的情況下返回GET並以POST Request類型觸發路由。
所有這些的原因是我想根據以下要求將CSS類添加到元素。
if form is submitted
if $errors->has('name') //is there an error for name(example)
add 'has-error' class
else
add 'has-success' class
endif
endif
有人知道解決方案嗎?
我認為您想實現以下目標:
if( old('name') ){ // name has been submitted
if( $errors->first('name') ){ // there is at least an error on it
// add error class
}else{ // has been submitted without errors
// add valid class
}
}
在輸入字段中是這樣的:
<input name="name" class="validate{{ old('name') ? ( $errors->first('name') ? ' invalid' : ' valid') : '' }}" type="text" value="{{ old('name') }}">
里克,
您可以驗證,您應該看看Laravel中的validate函數。 您可以驗證您發送的輸入,如果出現錯誤,則將其發送回視圖。
有關示例,請查看網址: https : //laravel.com/docs/5.1/validation
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.