你好,我是新來laravel,現在我面臨這個錯誤BadMethodCallException in Macroable.php line 74: Method save does not exist.
Macroable.php中的BadMethodCallException第74行:方法保存不存在。 Laravel 5.2
如果我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}', '[email protected]');
Route::post('/t/{id}', '[email protected]');
查看
<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();
}
你想保存一個集合嗎? '$ to'是'TO :: all()'的結果,它應該返回一個'Collection'。 –
它只是一個文本區域消息以及一個ID和日期時間'例如'這是消息「添加在用戶ID 5'' ...我不知道爲什麼我得到它... –
我只是想在數據庫中存儲'id'和'result(message)'的列。 –