保存自定義的數據我想保存登記號碼的數據在我laravel項目中PHP -laravel如何從用戶輸入
Registration Number format: <dept code>-<current year>-XXX. For example, CSE-2012-001,
這裏部門代碼將來自UI端,當用戶選擇特定的部門。 我該怎麼做。任何想法或可能的解決方案?
這裏是我的控制器:
public function saveStudent(Request $request)
{
$this->validate($request,[
'email' => 'required|unique:students',
'contact_no' => 'required|regex:/(01)[0-9]{9}/',
]);
$student = new Student();
$student->name = $request->Input(['name']);
$student->email = $request->Input(['email']);
$student->contact_no = $request->Input(['contact_no']);
$student->address = $request->Input(['address']);
$student->date = $request->Input(['date']);
$student->department_id=$request->Input(['department_id']);
$student->registraion_number =
$teacher->save();
return redirect('teacherSavePage');
}
這裏是我的刀片查看:
@extends('layouts.master')
@section('title')
Student Registration
@endsection
@section('content')
@include('partials.message-block')
<div class="container" >
<h3> Student Registration </h3>
{!! Form::open(array('route' => 'saveStudent','class'=>'form-horizontal','method'=>'POST')) !!}
{!! Form::token(); !!}
{!! csrf_field() ; !!}
<div class="form-group">
<label>Name</label>
<input type="text" name="name" class="form-control" required placeholder="Name">
</div>
<div class="form-group">
<label>Email</label>
<input type="email" name="email" class="form-control" required placeholder="Email">
</div>
<div class="form-group">
<label>Phone</label>
<input type="text" name="contact_no" class="form-control" required placeholder="Phone">
</div>
<div class="form-group">
<label>Date</label>
<input type="text" id="txtDate" name="date" class="form-control" required >
</div>
<div class="form-group">
<label>Address</label>
<textarea class="form-control" name="address" required placeholder="Address" rows="3"></textarea>
</div>
<div class="form-group">
<label for="">Department</label>
<select class="form-control input-sm" required name="department_id" >
@foreach($department as $row)
<option value="{{$row->id}}">{{$row->name}}</option>
@endforeach
</select>
</div>
<button type="submit" class="btn btn-default">Submit</button>
{!! Form::close() !!}
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#txtDate').datepicker();
$('#txtDate').datepicker('setDate', 'today');
});
</script>
@endsection
怎麼樣$ student-> registraion_number = $ student-> department_id + year + xxx; + =連接並使用當前年份的輔助函數或Carbon和您的xxx值。 –