I have got the following piece of code inside a Repository class, which saves the model into the DB. However, that fails systematically.
/**
* Saves the subscriber
* @param $subscriber
* @return void
*/
public function save($subscriber)
{
// \DB::table('subscribers')->insert($subscriber)->toArray();
$this->subscriberModel->save($subscriber);
}
An alternative option that I found is commented out, which fails too.
The exception message that I receive is:
Argument 1 passed to Illuminate\Database\Eloquent\Model::save() must be of the type array, object given, ...
Update
I should point out that I am fairly new to Laravel, and wondering what are the common ways in Laravel to sort this out?
Update 2
I have saved the object, but had to use the following piece of code inside save($subscriber) :
$subscriberArray = [ "id" => $subscriber->getId(),
"email" => $subscriber->getEmail(),
"subscriber_source_id" => $subscriber->getSubscriberSourceId()
];
\DB::table('subscriber')->insert($subscriberArray);
This doesn't really help me to undestand the reason that I have to convert it to array first.
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1Tw63JM
via IFTTT
Aucun commentaire:
Enregistrer un commentaire