S
S
Sinus_3142021-11-22 10:17:39
Laravel
Sinus_314, 2021-11-22 10:17:39

How to pass data to the model?

Hello.

I'm building a laravel site with very simple functionality: entity output, filtering, pagination, navigation, etc.

The catch is that I do not take the data from the database, but from the api.

Question: is it possible to transfer data from api to a model so as not to change the laravel structure with models and controllers?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2021-11-22
@Sinus_314

You can transfer:

$data = $api->getJson();
$model = new YourModel($data);

But it's just easier to create your own models that are not related to Eloquent (you can add the HasAttributes trait to them if you like its behavior), and not try to pull a snake on a hedgehog. The "standard" model has a lot of everything tied to Eloquent and it will be difficult to replace it, it's better to slowly add the necessary functionality by hand.
Well, controllers do not care what objects to work with.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question