0
votes

I'm using Eloquent as a standalone package, I'm getting errors when creating a new object (but not when saving an existing one).

Test case:

$contact = new Carriercontact;
$contact->fname = 'test1';
$contact->save();

Model:

<?php
use \Illuminate\Database\Eloquent\Model as Eloquent;

class Carriercontact extends Eloquent {

    // const CREATED_AT = 'create_dt'; // todo: add this
    const CREATED_AT = false;

    const UPDATED_AT = 'lst_chg';

    protected $primaryKey = 'CarrContID';

    public function company()
    {
        return $this->hasOne('Carrier', 'CarrID', 'CarrID');
    }

    public function getName()
    {
        ob_start();
        if ( ! empty($this->salute)) echo trim($this->salute).' ';
        if ( ! empty($this->fname)) echo trim($this->fname).' ';
        if ( ! empty($this->minit)) echo trim($this->minit).' ';
        if ( ! empty($this->lname)) echo trim($this->lname);
        return trim(ob_get_clean());
    }
}

Table:

CREATE TABLE `carriercontacts` (
    `CarrContID` INT(11) NOT NULL AUTO_INCREMENT,
    `CarrID` INT(11) NULL DEFAULT NULL,
    `compno` VARCHAR(12) NULL DEFAULT NULL,
    `salute` VARCHAR(8) NULL DEFAULT NULL,
    `fname` VARCHAR(20) NULL DEFAULT NULL,
    `lname` VARCHAR(25) NULL DEFAULT NULL,
    `minit` VARCHAR(1) NULL DEFAULT NULL,
    `phone` VARCHAR(20) NULL DEFAULT NULL,
    `faxno` VARCHAR(14) NULL DEFAULT NULL,
    `cell` VARCHAR(15) NULL DEFAULT NULL,
    `after_hrs` VARCHAR(20) NULL DEFAULT NULL,
    `email` VARCHAR(75) NULL DEFAULT NULL,
    `comments` LONGTEXT NULL,
    `lst_chg` DATETIME NULL DEFAULT NULL,
    `chg_by` VARCHAR(10) NULL DEFAULT NULL,
    `is_deleted` TINYINT(1) UNSIGNED NULL DEFAULT '0',
    PRIMARY KEY (`CarrContID`),
    INDEX `CarrID` (`CarrID`),
    INDEX `lname` (`lname`, `fname`, `minit`)
);

Errors:

Message: array_key_exists(): The first argument should be either a string or an integer Filename: Eloquent/Model.php Line Number: 2649

Message: Missing argument 2 for Illuminate\Database\Eloquent\Model::setAttribute(), called in /home/umpbiz/www/_dev/cargosystems/application/vendor/illuminate/database/Illuminate/Database/Eloquent/Model.php on line 2439 and defined Filename: Eloquent/Model.php Line Number: 2430

Severity: Warning Message: Illegal offset type in isset or empty Filename: Support/Str.php Line Number: 356

Then the errors just cascade and the page locks up.

No issues with other models/tables, anyone have an idea what I'm missing?

1
Is the error coming from the second or third line of your code?Jonas Staudenmeir
@JonasStaudenmeir third line, where save() is called.Wesley Murch

1 Answers

1
votes

CREATED_AT can't be false, use null instead:

const CREATED_AT = null;