【发布时间】:2014-08-08 16:00:44
【问题描述】:
我有两张桌子:
管理员:
ID | username | password | mobileNumber | firstName | lastName
餐厅:
website | adminID | name
我有一个包含这些数据的 html 表单
restaurantName
website
username
password
mobileNumber
firstName
lastName
当我提交该表单时,我想将数据插入到 admin 表中,然后将带有 adminID 的数据插入到餐厅表中:
我试过这个:
$input = Input::all();
$admin = Admin::create(Input::only('username', 'password', 'mobileNumber', 'firstName', 'lastName'));
$data = [
'name' ,
Input::get('restaurantName'),
'website' => Input::get('website')
];
$restaurant = new Restaurant($data);
$admin->restaurant()->save($restaurant);
但我得到了这个例外:
BadMethodCallException
Call to undefined method Illuminate\Database\Query\Builder::save()
你能帮忙吗?
管理模式
class Admin extends Eloquent implements UserInterface, RemindableInterface {
use UserTrait, RemindableTrait;
public function restaurant(){
return $this->belongsTo('Restaurant', 'ID');
}
餐厅模型
class Restaurant extends Eloquent implements UserInterface, RemindableInterface {
use UserTrait, RemindableTrait;
public function admin(){
return $this->hasOne('Admin', 'adminID');
}
【问题讨论】:
标签: php mysql laravel laravel-4 blade