Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HW20 API, CRUD, Resources #531

Open
wants to merge 1 commit into
base: VMeshavkin/hw18
Choose a base branch
from
Open

Conversation

vetalm1
Copy link

@vetalm1 vetalm1 commented Jul 27, 2020

No description provided.

{
$data = $request->getFormData();
$this->advertsService->storeAdvert($data);
return 'saved';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно сразу вернуть сохраненый ресурс

public function update(StoreAdvertRequest $request, Advert $advert)
{
$this->advertsService->updateAdvert($advert, $request->all());
return 'Updated';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно сразу вернуть обновленый ресурсы это будет по REST

if($offset) $advert->skip($offset);

$advert->with('town', 'user', 'division');
return $advert->get(['adverts.*']); // ???
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если у вас будут join в запросе, то можете вернуть лишнее данные, это зашита от дурака)

if ($limit) $advert->take($limit);
if($offset) $advert->skip($offset);

$advert->with('town', 'user', 'division');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

messages зависимость тоже используете

@@ -38,6 +38,16 @@ public function paginateList($qty)
return Advert::with('town', 'user', 'division')->paginate($qty);
}

public function paginateListApi(int $limit, int $offset)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я бы предложил переименовать метод в getAdverts(int $limit, int $offset)
a with сделал бы в сервисе,

$adverts = $this->repository->getAdverts
$adverts->load(['town', 'user', 'division', 'messages'])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants