因此,我有一个函数,可以单击时用值1填充数据库中的列,现在我添加了一个输入字段,并且需要将来自新输入的文本保存在列decline_reason.
中>
这是我尝试做的事情:
public function cancelp(requ $request, $id)
{
Reports::find($id)->update(['status' => '0']);
Reports::find($id)->update(['decline_reason' => $request['decline_reason']]);
Session::flash('message', "Report declined");
return Redirect::back();
}
现在
带有按钮的视图,将值填充到我的列中
<div class="modal-body">
<label>Specify the reason</label>
<input name="decline_reason" class="form-control" type="text"/>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<a>{{ link_to('admin/reports/p/' . $report->id. '/action-cancel', 'Decline', ['class' => 'btn btn-danger btn-xs']) }}</a>
</div>
Route::get('admin/reports/p/{job}/action-cancel', 'ArticleController@cancelp');
报告模型
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Reports extends Model
{
protected $table = 'reports';
// public $timestamps = false;
protected $fillable = [
'user_id', 'username', 'user_id_posted', 'username_posted', 'news_id','opinion_id','event_id','career_solution_id', 'subject', 'why_reporting','why_reporting_message','additional_message','status', 'comment_id', 'decline_reason'
];
public function career_solutionReport()
{
return $this->belongsTo('App\CareerSolution','career_solution_id','id');
}
public function eventReport()
{
return $this->belongsTo('App\Event','event_id','id');
}
public function newsReport()
{
return $this->belongsTo('App\News','news_id','id');
}
public function opinionReport()
{
return $this->belongsTo('App\Opinion','opinion_id','id');
}
public function user()
{
return $this->belongsTo('App\User','user_id','id');
}
}
目前,该列在数据库中为null
。
答案 0 :(得分:1)
<a>{{ link_to('admin/reports/p/' . $report->id. '/decline', 'Decline', ['class' => 'btn btn-danger btn-xs']) }}</a>
Route::get('admin/reports/p/{job}/{action}', 'ArticleController@cancelp');
更改您的更新代码
public function cancelp($job,$action)
{
Reports::find($job)->update(['status' => '0','decline_reason' => $action]);
Session::flash('message', "Report declined");
return Redirect::back();
}
注意:确保您的报告模型的可填充值为status,decline_reason
class Reportsextends Model
{
protected $fillable = [
'status', 'decline_reason'
];
}
好像您想将其与输入字段一起传递。
<form method="POST" action="{{ route('report.submit') }}">
<input type="hidden" name="job_id" value="{{ $report->id }}">
<input type="hidden" name="decline_reason" value="decline">
{!! csrf_field() !!}
<button type="submit" class="btn btn-danger btn-xs" value="Submit">
</button>
</form>
Web.php
Route::post('admin/reports/submit', 'ArticleController@canclesubmit')->name('report.submit');
控制器
public function canclesubmit(requ $request)
{
Reports::find($request->job_id)->update(['status' => '0','decline_reason' => $request->decline_reason]);
Session::flash('message', "Report declined");
return Redirect::back();
}