Answer the question
In order to leave comments, you need to log in
How to use updateOrCreate?
There is an array with screenshots
[
{
"url": "http://asd.ru/qwe.jpg",
"uploaded": "true"
},
{
"url": "http://asdas.ru/qwe.jpg",
"uploaded": "true"
}
]
$array = [];
foreach ($params['screenshots'] as $screenshot) {
$array[] = Material::updateOrCreate([
'content' => $screenshot['url'],
], [
'episode_id' => $params['episode_id'],
'type_id' => 2,
'profile_id' => 2,
'content' => $screenshot['url'],
'meta' => true,
])->select(['episode_id', 'content', 'meta'])->get();
}
return $array;
{
"jsonrpc": "2.0",
"id": 10,
"result": [
[
{
"episode_id": 1,
"content": "http:\/\/asd.ru\/qwe.jpg",
"meta": true
},
{
"episode_id": 1,
"content": "123.jpg",
"meta": true
}
],
[
{
"episode_id": 1,
"content": "http:\/\/asd.ru\/qwe.jpg",
"meta": true
},
{
"episode_id": 1,
"content": "123.jpg",
"meta": true
}
]
]
}
Answer the question
In order to leave comments, you need to log in
Try like this:
// ...
$array[] = Material::updateOrCreate([
'content' => $screenshot['url'],
], [
'episode_id' => $params['episode_id'],
'type_id' => 2,
'profile_id' => 2,
'content' => $screenshot['url'],
'meta' => true,
])->only(['episode_id', 'content', 'meta']); // Используем коллекции
// ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question