laravel,使用Eloquent时从空值创建默认对象

时间:2014-11-23 23:57:01

标签: php laravel-4 codeception

我正在使用laravel和codeception ..

我想将表单的内容存储到一个名为网站的表中,我创建了一个模型Website.php,其中包含所记录的默认模板和一个资源WebsiteController.php。

根据代码,路由按预期工作。

我在WebsiteController.php的商店方法中有以下代码:

$website_name = Input::get('website_name');

$website = new Website;
$website->name = $website_name;       // line with the probleme
$website->save();

return 'success';

当我填写表单并发送它时,我收到错误:从空值创建默认对象,指向上面的注释行。

<?php

class Website extends Eloquent {
   // empty class
}

dd($ website)的输出;

object(Website)#158 (20) { ["fillable":protected]=> array(4) { [0]=> string(4) "link" [1]=> string(4) "type" [2]=> string(4) "name" [3]=> string(11) "description" } ["connection":protected]=> NULL ["table":protected]=> NULL ["primaryKey":protected]=> string(2) "id" ["perPage":protected]=> int(15) ["incrementing"]=> bool(true) ["timestamps"]=> bool(true) ["attributes":protected]=> array(0) { } ["original":protected]=> array(0) { } ["relations":protected]=> array(0) { } ["hidden":protected]=> array(0) { } ["visible":protected]=> array(0) { } ["appends":protected]=> array(0) { } ["guarded":protected]=> array(1) { [0]=> string(1) "*" } ["dates":protected]=> array(0) { } ["touches":protected]=> array(0) { } ["observables":protected]=> array(0) { } ["with":protected]=> array(0) { } ["morphClass":protected]=> NULL ["exists"]=> bool(false) }

0 个答案:

没有答案