我有一个表单,用户可以将项目发布到数据库,同时创建一个新用户,两者都链接在一起.
表中的Usersid和projects.user_id值.但是,我有一个小问题.如果我从users表中获取最后一个id,并使用那个+1来表示下一个id.但是如果用户在添加带有id的新项目之前被删除,那么当应用程序启动时它会变得非常混乱.
假设我在表格中将最后一个用户作为id 5.但是,有人删除了它,我在第二天用新用户创建了一个新项目.现在下一个id将是id 6.但根据我的代码,它在projects_table中反映了5,但在users_table中它变为6.
我想知道是否有人可以建议我使用一个能用于拥有正确身份证的功能?
获取最后一个ID的函数
public static function getLastRow(){
$data = DB::table('users')->select('id')
->orderBy('id', 'desc')
->first();
return $data->id;
}
Run Code Online (Sandbox Code Playgroud)
在验证器之前,我计算将其添加到项目的最后一个ID
$lastidplus = (int)User::getLastRow() + 1;
Run Code Online (Sandbox Code Playgroud)
在我的验证器中我有这个:
'user_id' => $lastidplus,
Run Code Online (Sandbox Code Playgroud)
注意::这有效,但如果以后将删除users表中的最后一行.在相应的项目表中会出现虚假ID的连锁反应,因为他总是会有1个不同之处.我想让那不可能.
我正在开发一个访问 sqlserver 数据库的 laravel 应用程序,我需要我的日期字段为datetime2. 问题是,如果我告诉迁移引擎创建一个如下所示的日期时间字段:
$table->dateTime('myDateTimeColumn');
Run Code Online (Sandbox Code Playgroud)
if 将创建一个datetime字段,而不是一个datetime2字段。
我怎样才能强制datetime2列,而不必在迁移后更改它们(这听起来很草率)?
所以我在我的项目中创建了一个文件上传功能.
但是,当我尝试它时,我收到此错误: Call to a member function isValid() on string
我的上传功能代码:
public function upload(Request $request){
$file = array('profielfoto' => $request->input('profielfoto'));
$rules = array('profielfoto' => 'required',);
$validator = Validator::make($file,$rules);
if($validator->fails()){
return redirect('/profiel')->withInput()->withErrors($validator);
}
else{
if($request->input('profielfoto')->isValid()){ //<- gives error
$destinationPath = 'assets/uploads';
$extension = $request->input('profielfoto')->getClientOriginalExtension();
$fileName = rand(1111,9999).'.'.$extension;
$request->input('profielfoto')->move($destinationPath,$fileName);
Session::flash('alert-success', 'Foto uploaden gelukt');
return redirect('/profiel');
}
else{
Session::flash('alert-danger', 'Foto uploaden mislukt');
return redirect('/profiel');
}
}
}
Run Code Online (Sandbox Code Playgroud)
从下面第4行的刀片视图中的表单是输入的位置!
<form method="POST" action="/profiel/upload" files="true">
{!! csrf_field() !!}
<input type="hidden" name="_method" value="PUT">
<input type="hidden" class="form-control id2" …Run Code Online (Sandbox Code Playgroud) 所以我想让我的<tr>'s可点击/链接到相应的页面.所有行都有一个按钮来删除行.不幸的是,当用户单击删除按钮时,它仍会在单击行时链接.我添加了代码,所以除了点击按钮之外它会这样做.所以它可以打开bootstrap modal删除确认.
我的剧本:
$('tr[data-href]:not(:button)').on("click", function() {
document.location = $(this).data('href');
});
$('tr button[data-target]').on("click", function() {
document.location = $(this).data('target');
});
Run Code Online (Sandbox Code Playgroud)
带有刀片foreach的HTML表格
<tr style="cursor:pointer;!important;" data-href="/bugs/{{$project->id}}">
<td>{{$project->created_at->format('d-m-Y')}}</td>
<td>{{$project->projectnaam}}</td>
<td>{{$project->liveurl}}</td>
<td>{{$project->developmenturl}}</td>
<td>{{$project->user->voornaam .' '. $project->user->tussenvoegsel .' '. $project->user->achternaam }}</td>
<td>{!! substr($project->omschrijvingproject,0,90) !!}</td>
<td class="text-right" >
<a href="/projectmuteren/{{$project->id}}" class="">
<button class="btn btn-success btn-xs wijzigKnop2" name="zoekProject" type="button" data-project="{{$project->projectnaam}}">
<i class="glyphicon glyphicon-pencil"></i>
</button>
</a>
<button type="button" class="btn btn-danger btn-xs" data-toggle="modal" data-target="#myModal{{$project->id}}">
<i class="glyphicon glyphicon-trash"></i>
</button>
</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
删除模式
<div class="modal fade" id="myModal{{$proj->id}}" tabindex="-1" role="dialog"> …Run Code Online (Sandbox Code Playgroud)