fork download
  1. <?php
  2.  
  3. $rows = [
  4. 0 => [
  5. 'device_id' => 3
  6. 'price' => 321312
  7. ],
  8. 1 => [
  9. 'device_id' => 1,
  10. 'price' => 1123
  11. ]
  12. ];
  13.  
  14. foreach ($rows as $row){
  15. Validator::make($row, [
  16. '*.device_id' => ['required', 'integer', 'exists:App\Device,id', Rule::unique('prices')
  17. ->where('device_id', $row['device_id'])
  18. ],
  19. '*.price' => ['required', 'numeric', 'min:0', 'max:16777215'],
  20. ])
  21. ->validate();
  22. }
  23.  
  24. foreach ($rows as $row){
  25. Price::create([
  26. 'device_id' => $row['device_id'],
  27. 'price' => $row['price'],
  28. ]);
  29. }
  30.  
Runtime error #stdin #stdout #stderr 0.02s 24460KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Parse error:  syntax error, unexpected ''price'' (T_CONSTANT_ENCAPSED_STRING), expecting ']' in /home/UZIyjI/prog.php on line 6