Skip to content

SubDocuments #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
brunocascio opened this issue Dec 9, 2013 · 5 comments
Closed

SubDocuments #84

brunocascio opened this issue Dec 9, 2013 · 5 comments

Comments

@brunocascio
Copy link

How attach a embbed document in a model?

For example in post an user.

Post: {
title: 'something',
body: 'somethng',
user: {
_id: '1267a6767hs67',
name: 'Bruno Cascio',
}
}

How to insert post with that model?

@brunocascio
Copy link
Author

Posible Solution:

Auth::user()->_id, 'name' => Auth::user()->name); ``` $validation = Post::validate( $data ); if ( $validation->passes() ) { $post = Post::create( $data ); return Response::json( array('flash' => 'Publicado!')); } else { return Response::json( array('flash' => $validation->messages()->first()), 500 ); } ``` } ?>

@jenssegers
Copy link
Contributor

There a multiple ways to store subdocuments. You can do it the Eloquent way with relations, or do it manually and insert arrays/objects as model attributes.

@brunocascio
Copy link
Author

With eloquent it's implemented?

$user = User::find('a23s988a8sa98s9')->get();

$post->user = $user;

$post->user() = $user;

i get error mass assignment...

@jenssegers
Copy link
Contributor

Check out 'inserting related models' on http://laravel.com/docs/eloquent#relationships. This will not create an actual subdocument, but will store a reference to the related object.

@brunocascio
Copy link
Author

I don't understand, but now it's working :|

Thanks and i'm sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants