Skip to content

Instantly share code, notes, and snippets.

@NiltonMorais
Created June 15, 2016 04:11
Show Gist options
  • Select an option

  • Save NiltonMorais/27b546ac91a2718167259a82931ef62f to your computer and use it in GitHub Desktop.

Select an option

Save NiltonMorais/27b546ac91a2718167259a82931ef62f to your computer and use it in GitHub Desktop.
<?php
namespace DeliveryUrbano\Http\Controllers\Api\Client;
use \DeliveryUrbano\Http\Controllers\Controller;
use DeliveryUrbano\Http\Requests\CheckoutRequest;
use DeliveryUrbano\Repositories\OrderRepository;
use DeliveryUrbano\Repositories\UserRepository;
use DeliveryUrbano\Services\OrderService;
use \LucaDegasperi\OAuth2Server\Facades\Authorizer;
class ClientCheckoutController extends Controller {
/**
* @var OrderRepository
*/
private $orderRepository;
/**
* @var UserRepository
*/
private $userRepository;
/**
* @var OrderService
*/
private $orderService;
private $with = ['client', 'cupom', 'items'];
public function __construct(OrderRepository $orderRepository, UserRepository $userRepository, OrderService $orderService) {
$this->orderRepository = $orderRepository;
$this->userRepository = $userRepository;
$this->orderService = $orderService;
}
public function index(CheckoutRequest $request) {
dd("passou");
$id = Authorizer::getResourceOwnerId();
$userId = $id;
$orders = $this->orderRepository
->skipPresenter(false)
->with($this->with)
->scopeQuery(function($query) use ($userId){
return $query->where('user_client_id','=',$userId);
})->paginate();
return $orders;
}
public function store(CheckoutRequest $request) {
$data = $request->all();
$data['user_client_id'] = Authorizer::getResourceOwnerId();
$order = $this->orderService->create($data);
return $this->orderRepository
->skipPresenter(false)
->with($this->with)
->find($order->id);
}
public function show($id) {
return $this->orderRepository
->skipPresenter(false)
->with($this->with)->find($id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment