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

It is being set automatically after you save the model : $spot->id is available after you save or create a model

Last updated 2 years ago.
0

@bigsinoos

oh wow, that was less painful than expected.

follow up question, how would i include the new $spot_id along with:

$tag = Tag::create(array_only($tagData, ['user_id', 'tag_name']));

I've tried this to no avail

//create spot
		$spot = new Spot;
        $spot->user_id 			= Input::get('user_id');
        $spot->latitude 		= Input::get('lat');
        $spot->longitude 		= Input::get('lng');
        $spot->spot_name		= Input::get('spot_name');
        $spot->location_notes 	= Input::get('location_notes');
        $spot->comments 		= Input::get('comments');
        $spot->save();

        //get spot_id for tags table
        $spot_id = $spot->spot_id;

        //dynamic tags
		$tags = Input::get('tags');
		foreach ((array) $tags as $tagData)
		{
			$tag = new Tag;
			$tag->spot_id = $spot_id;
			$tag->user_id = Input::get(array_only($tagData, ['user_id']));
			$tag->tag_name = Input::get(array_only($tagData, ['tag_name']));
			$tag->save();
		    
		}

I'm not sure on the eloquent syntax to handle this. I've made a new column in my database to accommodate it.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.