当我想将数组添加到数据库时:
$tab = array(
'name' => Input::get('name'),
'user_id' => Auth::id()
);
Foto::create($tab);
MODEL:
<?php
class Foto extends Eloquent {
public static function create($name) {
returnDB::table('galleries')->insert(array('name' => $name['name'], 'user_id' => $name['user_id']));
}
}
模型应该怎么样?
答案 0 :(得分:0)
在控制器(FotoController.php)中,您可以编写如下内容:
class FotoController extends BaseController {
public function create() {
$foto= new Foto(
array(
/*Field's form*/
"name" => Input::get("name"),
"user_id" => Input::get("user_id"),
)
);
$foto->save();
}
}