It is being set automatically after you save the model : $spot->id
is available after you save
or create
a model
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community