Php 如果单击按钮,如何将布尔值设置为true?
如果单击当前Php 如果单击按钮,如何将布尔值设置为true?,php,laravel,Php,Laravel,如果单击当前id的按钮,我试图将我的isApprove布尔值设置为true 迁移: public function up() { Schema::create('approve_document', function (Blueprint $table) { $table->increments('id'); $table->integer('approve_id')->unsigned(); $table-&g
id
的按钮,我试图将我的isApprove
布尔值设置为true
迁移:
public function up()
{
Schema::create('approve_document', function (Blueprint $table)
{
$table->increments('id');
$table->integer('approve_id')->unsigned();
$table->integer('document_id')->unsigned();
$table->integer('requestedBy')->unsigned();
$table->foreign('approve_id')->references('id')->on('approves')->onDelete('cascade');
$table->foreign('document_id')->references('id')->on('documents')->onDelete('cascade');
$table->foreign('requestedBy')->references('id')->on('users')->onDelete('cascade');
$table->boolean('isApprove');
$table->dateTime('dateReceived')->default(DB::raw('CURRENT_TIMESTAMP'));
$table->timestamp('dateModified')->default(DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
});
}
控制器:
public function documentsSentForApproval()
{
$pendingDocumentLists = DB::table('approve_document')
->select('documents.title', 'documents.content', 'categories.category_type', 'users.username', 'approve_document.dateReceived', 'documents.id', 'approves.approver_id', 'approve_document.document_id', 'approve_document.isApprove')
->join('documents', 'documents.id', '=', 'approve_document.document_id')
->join('categories', 'categories.id', '=', 'documents.category_id')
->join('approves', 'approves.id', '=', 'approve_document.approve_id')
->join('users', 'users.id', '=', 'approves.approver_id')
->where('approver_id', '=', Auth::id())
->orWhere('requestedBy', '=', Auth::id())
->get();
return view ('document.pending')
->with('pendingDocumentLists', $pendingDocumentLists);
}
视图:
@foreach($pendingDocumentList作为$list)
{{$list->title}
{{strip_标记(substr($list->content,0,50))}{{strlen($list->content)>50?“:''}
{{$list->category_type}
{{$list->username}
{{date('M,j,Y',strottime($list->dateReceived))}
删除
@如果(Auth::id()=$list->approver\u id)
拒绝
@恩迪夫
@endforeach
我现在有点困在这里了。其中,如果我点击批准按钮,我将获得文档
的当前id,但我需要在此处设置一个条件,将其isApprove
设置为true。有什么帮助吗?我怎样才能做到这一点
逻辑:
如果批准了($list->document\u id)
。将当前文档id的isApprove
列设置为true
可以查看以下内容:
新增
<input type="hidden" name="approved" value="0">
当使用javascript单击按钮时,将值更改为1
也可以通过ajax发送,但不要忘记添加令牌 p.s true和false可替换为1 ad 0您可以查看以下内容: 新增
<input type="hidden" name="approved" value="0">
当使用javascript单击按钮时,将值更改为1
也可以通过ajax发送,但不要忘记添加令牌
p.s true和false可替换为1 ad 0谢谢。my db的当前值为0。所以我想我应该把value改为
1
。是的。你应该$approved=1将作为$approved=true mysql boolean另存为tinyints是否应在我的视图或javascript函数下包含此输入类型=“hidden”?您可以在视图中包含,并使用javascript按钮单击事件更改值谢谢。my db的当前值为0。所以我想我应该把value改为1
。是的。你应该$approved=1将作为$approved=true mysql boolean另存为tinyints是否应在我的视图或javascript函数下包含此输入类型=“hidden”?您可以在视图中包含,并使用javascript按钮单击事件更改值