-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyAjaxResponse.php
38 lines (34 loc) · 1.08 KB
/
MyAjaxResponse.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace Vanchelo\AjaxResponse;
/**
* Почему я использую use и as?
* Потому что если вы воспользуетесь Response фасадом Laravel, названия будут конфликтовать
*/
use Vanchelo\AjaxResponse\Response as AjaxResponse;
class MyAjaxResponse extends AjaxResponse
{
/**
* Для еще большего удобства
* $response->todo(['id' => 10, 'title' => 'Какая-то важная задача']);
* $response->todos(
* ['id' => 10, 'title' => 'Какая-то важная задача'],
* ['id' => 11, 'title' => 'Еще одна важная задача']
* );
*
* @param string $name
* @param array $arguments
*
* @return $this
*/
public function __call($name, $arguments)
{
if (count($arguments) == 1) {
$this->data[$name] = $arguments[0];
} else {
if (count($arguments) > 1) {
$this->data[$name] = $arguments;
}
}
return $this;
}
}