繁体   English   中英

Laravel Blade请求方法

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM