正在重新创建表单以使用DB值和表单中的旧值进行更新吗?

问题描述 投票:0回答:1

一切正常,我只想在更新表单上显示数据库值。当我在值中添加{{$ student-> roll_id}}时,它在创建表单时显示问题。如何解决此问题,以便在更新表单中出现DB值,并且创建表单为空?

// form.blade.php
@if($layout == 'index')
<form action="{{ url('/store') }}" method="post" enctype="multipart/form-data">
@elseif($layout == 'edit')
<form action="{{ url('/update/'.$student->id) }}" method="post" action="patchlink" enctype="multipart/form-data">
    @method('PATCH')
@endif        
@csrf

    <div class="form-group">
        <label>Roll Id</label>
        <input name="roll_id" value="{{ old('roll_id') }}" type="text" class="form-control"  placeholder="Enter your Roll Id">
        <small class="text-danger">{{ $errors->first('roll_id') }}</small>
    </div>
    <div class="form-group">
        <label>First Name</label>
        <input name="firstName" value="{{ old('firstName') }}" type="text" class="form-control"  placeholder="Enter the first name">
        <small class="text-danger">{{ $errors->first('firstName') }}</small>
    </div>


    <div class="form-group">
        <label>Second Name</label>
        <input name="secondName" value="{{ old('secondName') }}" type="text" class="form-control"  placeholder="Enter second name">
        <small class="text-danger">{{ $errors->first('secondName') }}</small>
    </div>

    <div class="form-group">
        <label>Faculty</label>
        <input name="faculty" value="{{ old('faculty') }}" type="text" class="form-control"  placeholder="Enter the faculty">
        <small class="text-danger">{{ $errors->first('faculty') }}</small>
    </div>
    <div class="form-group">
        <label>Assignment Title</label>
        <input name="assignment_title" value="{{ old('assignment_title') }}" type="text" class="form-control"  placeholder="Enter the assignment title">
        <small class="text-danger">{{ $errors->first('assignment_title') }}</small>
    </div>
    <div class="form-group">
        <label>Assignment</label>
        <input name="assignment_file" value="{{ old('assignment_file') }}" type="file" class="form-control"  placeholder="">
        <small class="text-danger">{{ $errors->first('assignment_file') }}</small>
    </div>
    <input type="submit" class="btn btn-info" value="Save">
    <input type="reset" class="btn btn-warning" value="Reset">

</form>
laravel-5.8
1个回答
0
投票

感谢互联网资源,我解决了这个问题。到目前为止,对我来说,在值中应用Ternary Operator是最好的方法。

<div class="form-group">
    <label>Roll Id</label>
    <input name="roll_id" value="{{ $layout=='index' ? old('roll_id') : $student->roll_id }}" type="text" class="form-control"  placeholder="Enter your Roll Id">
    <small class="text-danger">{{ $errors->first('roll_id') }}</small>
</div>
© www.soinside.com 2019 - 2024. All rights reserved.