-
Notifications
You must be signed in to change notification settings - Fork 13
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
base: VMeshavkin/hw18
Are you sure you want to change the base?
Conversation
{ | ||
$data = $request->getFormData(); | ||
$this->advertsService->storeAdvert($data); | ||
return 'saved'; |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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.*']); // ??? |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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'])
No description provided.