Laravel在控制器中进行表单验证

时间:2015-06-11 15:00:00

标签: php mysql laravel

我有3个表,用户,公司,属性(具有各种价值)

用户拥有account_id:company abbreviation + account number (GOOGLE-01234)

缩写来自公司表,帐号填写在表格中。

因此,公司有一个数字,其中下一个用户account_id将被放入属性表中。因此,如果公司的account_nr_start 1000,则每个新用户将为1000+ - > 1001 - > 1002并计数。但是也可以设置一个自己的数字,例如500,但这需要进行验证。

所以它从abbreviation获得companyaccount_nr_startattributes获得account_idusers变为$data = User::lists('account_id');

因此,我使用public function store(CreateUserRequest $request, User $user, Attribute $attribute) { $new_attribute = $attribute ->where('company_id', '=', Auth::user()->company->id) ->where('attribute', '=', 'account_nr_start') ->first(); $new_attribute->fill($request->only('company_id', 'value'))->save(); $user->fill($request->only('email', 'firstname', 'lastname', 'middlename', 'usertype_id', 'active', 'company_id', 'title', 'btw_nr', 'kvk_nr', 'bic', 'iban', 'birthday', 'mobile', 'telephone', 'country', 'city', 'postal_code', 'house_nr', 'street')); $user->account_id = $request['abbreviation'] . "-" . $request['value']; $data = User::lists('account_id'); if ($user->account_id = $data) { return 'Used!'; } else { return 'Usable!'; // $user->password = Hash::make($request->input('password')); // // $user->save(); // // return redirect()->route('user.index'); } $user->password = Hash::make($request->input('password')); $user->save(); return redirect()->route('user.index'); 获取所有account_id,然后使用if / else语句检查是否使用了account_id。

因为我现在所做的不起作用!

表:

enter image description here

enter image description here

enter image description here

控制器:

@if(isset($user->account_id))
    <div class="form-group">
        {!! Form::label('account_id', trans('common.account_id'), ['class' => 'form-label col-sm-3
        control-label text-capitalize']) !!}
        <div class="col-sm-2">
            {!! Form::text('disabledAbbreviation', $user->company->abbreviation, ['class' => 'form-control
            col-sm-3', 'id' => 'disabledInput', 'disabled']) !!}
            {!! Form::hidden('abbreviation', $user->company->abbreviation) !!}
        </div>
        <div class="col-sm-4  {{ $errors->has('account_nr') ? 'has-error' : '' }}">
            {!! Form::text('account_nr', null, ['class' => 'form-control col-sm-9', 'placeholder' =>
            trans('common.account_id') ]) !!}
            {!! $errors->first('account_nr', '<span class="help-block">:message</span>') !!}
        </div>
    </div>

@else
    <div class="form-group">
        <div class="{{ $errors->has('value') ? 'has-error' : ''}}">
            {!! HTML::decode (Form::label('account_id', trans('common.account_id').'<span class="asterisk"> *</span>',
            ['class' => 'form-label col-sm-3 control-label text-capitalize'])) !!}
        </div>
        <div class="col-sm-2">
            {!! Form::text('disabledAbbreviation', $abbreviation, ['class' => 'form-control col-sm-3', 'id'
            => 'disabledInput', 'disabled']) !!}
            {!! Form::hidden('abbreviation', $abbreviation) !!}
        </div>
        <div class="col-sm-4  {{ $errors->has('value') ? 'has-error' : '' }}">
            {!! Form::text('value' , $account_nr[0]->value+1, ['class' => 'form-control col-sm-9',
            'placeholder' => trans('common.account_id') ]) !!}
            {!! $errors->first('value', '<span class="help-block">:message</span>') !!}
        </div>
    </div>
@endif

刀片:

<ul id="nav">
  <li>cats</li>
</ul>
<ul>
  <li>dogs</li>
</ul> 

#nav li {color:green}

0 个答案:

没有答案