这是我的create.blade.php:
<script type="text/javascript">
$(document).ready(function(){
var x =0;
$(".add-row").click(function(){
x++;
$("table > tbody").append('<input class="form-control" type="text" name="MFI" placeholder="Major Final Output" id="MFI" value="Participate in school activities">');
}); //add input box
});
NotesController.php
public function store(Request $request)
print_r($_POST);
$ipcrId = Note::find($request->ipcr_id);
foreach ($request->MFI as $key => $value) {
$ipcrId->ipcr()->create([
'MFI' => $request->MFI[$key]
// repeat for other fields
]);
}
Note.php
class Note extends Model
{
protected $fillable= ['successIndicator','actualaccomplishments',
'distribution','Q1','E2','T3',' A4','Ave',
'Remarks','ipcr_id'];
public function ipcr()
{
return $this->belongsTo(ipcr::class);
}
}
ipcrController.php
public function store(Request $request)
{
$dataInput= $request->all();
$user= Auth::user();
$user->ipcr()->create($dataInput);
//$sql = "insert ";
//ipcr::create($dataInput);
return redirect('/ipcr');
我得到了
NotesController.php第55行中的FatalErrorException:在null上调用成员函数ipcr()
当我print_r()
时,我得到了txtbox的值:
Array ( [MFI] => Array ( [0] => Participate in school activities )
[_token] => mLuXcpnazy73KpKf1GY4WPLeVQcC1601KvbMHX4x
)