1 year ago

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

Posted 1 year ago by robjbrain

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

                    .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() {}

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?

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.