J
J
jazzus2019-01-24 22:01:42
Laravel
jazzus, 2019-01-24 22:01:42

How to pass object in Resource format from blade to VUE?

You need to pass the product in resource format to the Vue component from the template blade.
I know that it can be done

<sticker-statuses
:object="{{json_encode($product)}}"
>
</sticker-statuses>

need something like this
<sticker-statuses
:object= new ProductResource($product)
>
</sticker-statuses>

But I don't know how.
UPDATE
Temporarily did so AND in the model
:object="{{json_encode($product->toResource())}}"
public function toResource()
  {
    return new ProductResource($this);
  }

But that won't answer this question.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
ajaxtelamonid, 2019-01-25
@jazzus

How can js accept a php class? What do you think should be in :object physically ? There can only be a line, what can it be? A magical php-class serializer that js can decipher and understand?
There can only be json, because js understands it and makes a js object out of it automatically. Therefore, your current decision is the final decision.

S
Sergey Ananiev, 2019-01-29
@yoj_nc

:resource="{{ json_encode($users->toResponse($request)->getData()) }}"

well, or prepare a string in the controller and pass it to the view so as not to drag the request

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question