您好我是laravel的新手,现在我遇到了这个错误BadMethodCallException in Macroable.php line 74: Method save does not exist.
如果我var_dump(); die();
所有输出然后我得到所有这些输出但是当我使用save方法将结果保存到数据库时它会给我save method does not exist
这个错误。我不知道我的代码在哪里,我做错了。
请参阅路线控制器和视图以获得正确理解。提前谢谢。
public function td($id) {
$tn = $this->t->getAllTn();
$to = $this->t->getAllTo();
$time = Carbon\Carbon::now(); // current time
$time->toDateTimeString(); // converting time to string
if((isset($_POST["n"]) && !empty($_POST["n"]))) {
$tn->t_type_id = Input::get('options');
$tn->d_id = $id;
$tn->result = Input::get('message');
$tn->date = $time;
// var_dump($tn->date);
// var_dump($tn->t_type_id);
// var_dump($tn->d_id);
// var_dump($tn->result);
// die();
Session::flash('message', 'Your tn has been added.');
$tn->save();
} else if((isset($_POST["o"]) && !empty($_POST["o"]))) {
$to->d_id = $id;
$to->outcome = Input::get('message');
$to->date = $time->toDateTimeString();
// var_dump($to->d_id);
// var_dump($to->outcome);
// var_dump($to->date = $time->toDateTimeString());
// die();
Session::flash('message', 'Your to has been added.');
$to->save();
}
return redirect('/t');
}
Route::get('/t/{id}', 'TController@td');
Route::post('/t/{id}', 'TController@td');
<div class="form-group">
<form action="/t/{{ $d['id'] }}" method="post">
{{ csrf_field() }}
<div class="panel-body"><h4>Heading here</h4></div>
<select class="form-control" id="options" name="options" style="width:100%" type="checkbox">
@foreach($t as $t)
<option value="{{ $t->id }}">{{ $t->type }}</option>
@endforeach
</select>
</div>
<div class="col-md-4" id="value" align="center">
<div class="panel panel-warning">
<div class="panel-heading">
Enter text below
</div>
<div class="form-group has-success">
<textarea class="form-control" id="message" name="message" placeholder="Please enter your message here..." rows="5"></textarea>
<input type="submit" class="btn btn-primary" name="n" value="A-N">
<input type="submit" class="btn btn-primary" name="o" value="A-O">
</div>
</form>
<!-- Notes: <br/>-->
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
function hide() {
$("#value").hide();
$("#h").hide();
$("#search").hide();
}
function show() {
$("#value").show();
$("#h").show();
$("#search").show();
}
function initHandlers() {
$("#options").on('click', function() {
show();
});
}
hide();
initHandlers();
</script>
public function getAllTn() {
return TN::all();
}
public function getAllTO(){
return TO::all();
}
答案 0 :(得分:1)
您实例化Model
的方法是错误的。尝试类似:
$to = new TO();
$to->d_id = $id;
$to->outcome = Input::get('message');
$to->date = $time->toDateTimeString();
$to->save();
答案 1 :(得分:0)
您不需要获取所有项目来更新具有相同数据的所有项目吗?
如果模型字段是可填写的,您可以只是批量分配它们。
AbstractAnnotationConfigDispatcherServletInitializer
不确定您是否只需要更新TN表中的1个或很多项目?