robjbrain
237
3
Vue

What techniques are people using to work with Eloquent objects in VueJS?

Posted 9 months ago by robjbrain

I've been going through alot of examples of using VueJS with Laravel and i'm constantly seeing things like this:

        axios
                    .post('/api/post' + this.postId, {
                        foo: 'foo',
            bar: 'bar'
                    })
                    .then(response => {
                        // yay success
                    })
                    .catch(error => {
                        // oh no, an error
                    });

And you can imagine this happening in more than one place across a site. It seems it would be far nicer to have.

class Post extends Model {
    method save() {}
}
post.save()

But all the packages and libraries i've found that try to replicate this sort of thing barely seem maintained. It definitely doesn't seem to be the norm to use one.

There's also more advanced stuff like eloquent relationships. e.g:

for (comment of post.comments) {
    // You probably want this to be a Comment class?
    comment.someMethod();
} 

Writing all that functionality yourself could get really complicated really quickly.

So I wandered what approaches people are taking to replicate their laravel models on the JS side?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.