Support the ongoing development of Laravel.io →
Input Database Eloquent
Last updated 2 years ago.
0

Make sure that every $lesson item in foreach is an array.

$lesson = "Not an array, a string";
echo $lesson['lesson_id'];

// Warning: Illegal string offset 'lesson_id' in ...
Last updated 2 years ago.
0

Thanks mgsmus,

Yeah, in this case, the array descibed in the OP is the only item going through. As you can see, all should be fine - unless I am missing something obvious?

It's driving me mad!

Last updated 2 years ago.
0

Can you try this for me:

...
'lesson_id'    => isset($lesson['lesson_id']) ? (int)$lesson['lesson_id'] : null,
Last updated 2 years ago.
0

You can't use isset() inside an array like that. I'll sort it outside the array and report back. It's late here in the UK - beer o clock.

Thanks again. I'll jump on this in the morning.

Cheers

Last updated 2 years ago.
0

Hmmm. This is still a little odd. I've altered the code a little to reuse my update method for single items.

Everything is saving, however, I am getting:

Call to a member function save() on a non-object

Everything is saving as it should though!! ANNOYING!!

If I take off the if(isset(...)) on the update, it is still complaining of ILLEGAL OFFSET. But it isn't. The values are there in the array being sent through. I am 100% of that.

Any ideas?

###Mass-update

foreach($data as $id=>$lesson)
{
	$this->update($id, $lesson);
}

###Update method

$calendar = Calendar::find($id);

if(isset($data['name'])) 		$calendar->name  		= $data['name'];
if(isset($data['lesson_id'])) 	$calendar->lesson_id     = (int)$data['lesson_id'];
if(isset($data['location_id'])) 	$calendar->location_id   = (int)$data['location_id'];
if(isset($data['room'])) 		$calendar->room            = $data['room'];
if(isset($data['total_students'])) $calendar->total_students = (int)$data['total_students'];
if(isset($data['lead_tutor_id'])) $calendar->lead_tutor_id   = (int)$data['lead_tutor_id'];
if(isset($data['secondary_tutors_id'])) $calendar->secondary_tutors_id  = (int)$data['secondary_tutors_id'];
if(isset($data['message'])) 	$calendar->message         = $data['message'];
if(isset($data['lesson_plan'])) 	$calendar->lesson_plan     = $data['lesson_plan'];

 // Update each bad boy
 $calendar->save();
Last updated 2 years ago.
0

try changing

$calendar = Calendar::find($id);

to

$calendar = Calendar::findOrFail($id);

And see if you get any ModelNotFound exceptions

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

T2theC t2thec Joined 5 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.