php - 每个纪念品都会生成一个序列号
问题描述
我需要为每个纪念品生成一个序列号(在每一列中,不同的序列号)例如,纪念品 1 的序列号将是“AK0001”。我希望“AK”永久(无法更改)在那里。但对于“0001”则不然。它可以随机变化
我使用 laravel 5.4 及以下,adminlte,heidisql
我只是在纪念品的每一列中添加了另一行序列号
纪念品控制器.php
public function create()
{
return view('admin.souvenir.create');
}
public function store(Request $request)
{
$souvenir = new Souvenir;
$souvenir->name = $request->name;
$souvenir->dateReceived = $request->dateReceived;
$souvenir->description = $request->description;
$souvenir->receivedFrom = $request->receivedFrom;
$souvenir->location = $request->location;
$souvenir->status = $request->status;
$souvenir->save();
if( !$souvenir->save() ){
return redirect()
->route('admin.souvenir.index')
->with('error', "Error creating souvenir");
}
return redirect()
->route('admin.souvenir.index')
->with('success', "Souvenir created successfully!");
}
纪念品表迁移.php
class CreateSouvenirTable extends Migration
{
public function up()
{
Schema::create('souvenir', function( Blueprint $table )
{
$table->increments('id');
$table->string('serNumber');
$table->string('name', 100);
$table->date('dateReceived');
$table->text('description');
$table->string('receivedFrom', 100);
$table->string('location', 100);
$table->string('status', 100);
});
}
创建.blade.php
<div class="form-group">
<div class="row">
<label class="col-md-3">Series Number</label>
<div class="col-md-6">
<input type="text" name="serNumber" class="form-control">
</div>
<div class="clearfix"></div>
</div>
</div>
意见 - index.blade.php
<section class="content">
<div class="container-fluid">
<p>
<a href="{{ route('admin.souvenir.create') }}" class="btn btn-primary">Add New Souvenir</a>
</p>
<table class="table table-bordered table-striped">
<tr>
<th>ID</th>
<th>Series Number</th>
<th>Name</th>
<th>Date</th>
<th>Location</th>
<th>Status</th>
<th>Action</th>
</tr>
@foreach($souvenir as $s)
<tr>
<td>{{ $s->id }}</td>
<td>{{ $s->serNumber }}</td>
<td>{{ $s->name }}</td>
<td>{{ $s->dateReceived }}</td>
<td>{{ $s->location }}</td>
<td>{{ $s->status }}</td>
<td>
<a href="{{ route('admin.souvenir.edit', $s->id) }}" class="btn btn-primary btn-block">Edit </a>
<a href="{{ route('admin.souvenir.show', $s->id) }}" class="btn btn-success btn-block"> View </a>
<a href="javascript:void(0)" onclick="$(this).parent().find('form').submit()" class="btn btn-danger btn-block">Delete</a>
<form action="{{ route('admin.souvenir.destroy', $s->id) }}" method="post">
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
</td>
</tr>
@endforeach
</table>
</div>
</section>
@endsection
解决方案
如果您想更改最后四个区域,请尝试使用
$fourdigitrandom = rand(1000,9999);
然后与AK连接
$string= "AK" .$fourdigitrandom;
推荐阅读
- python - python中具有范围的图形函数
- jquery - 如何对页面上的多个音频文件使用相同的 javascript?
- amazon-web-services - SNS和SQS访问问题,收不到消息
- javascript - 从类列表 JavaScript 中删除一个类
- excel - 基于所选字段的返回列表
- azure-active-directory - 逻辑应用和配置 Office 365 电子邮件
- javascript - 我们如何使用 Javascript 在 Android / iOS 的 Chrome 移动浏览器中检测 onTabClosed(event)
- python - os.listdir() 以混合顺序读取文件
- javascript - v-calendar 问题,如何根据对象数组列表中的日期禁用日期
- android - 错误应用程序:transformClassesWithFirebasePerformancePluginForDebug 失败