Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Laravel] save vs update
Terrorizer
post
Post #1





Grupa: Zarejestrowani
Postów: 345
Pomógł: 3
Dołączył: 31.03.2012

Ostrzeżenie: (0%)
-----


Cześć!

Czy istnieje jakaś sensowna różnica pomiędzy update i save?

A może ja zwyczajnie źle z tego korzystam?

  1. namespace App\Services;
  2.  
  3. use App\Resource as Resource;
  4. use Illuminate\Support\Facades\Auth;
  5.  
  6. class ResourcesService
  7. {
  8.  
  9. public function addResources1($userId, $wood, $stone, $food, $gold)
  10. {
  11. $resources = new Resource;
  12. $resources = $resources->where('userId', $userId)->update([
  13. 'wood' => $wood,
  14. 'stone' => $stone,
  15. 'food' => $food,
  16. 'gold' => $gold,
  17. ]);
  18. }
  19.  
  20. public function addResources2($userId, $wood, $stone, $food, $gold)
  21. {
  22. $resources = new Resource;
  23. $resources = $resources->where('userId', $userId)->first();
  24. $resources->wood = $wood;
  25. $resources->stone = $stone;
  26. $resources->food = $food;
  27. $resources->gold = $gold;
  28. $resources->save();
  29. }
  30. }


Ten post edytował Terrorizer 6.06.2020, 12:18:19
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 21.12.2025 - 18:19