Laravel Oito
Criador
Leandro Ozorio
Error
Manager
Carlos Ferreira
Olá, Leandro!
Tudo bem?
Tem o código no GitHub?
Preciso ver com mais detalhes para conseguir te ajudar a identificar onde errou.
Criador
Leandro Ozorio
Boa tarde, tudo bem
Eu estava aplicando, em outro projeto, não é o projeto do curso.
getAll url:
https://fea.capital/api/nse/billpayments
// aqui está funcionando.
Agora passando o parâmetro $transactionId
http://https://fea.capital/api/nse/billpayments/7612628
// aqui ao tentar buscar pelo $transactionId, não obtive sucesso.
Criador
Leandro Ozorio
# Controller
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Resources\BillPaymentsResource;
use App\Services\NseService;
use Illuminate\Http\Request;
class NseController extends Controller
{
protected $nseService;
public function __construct(NseService $nseService)
{
$this->nsaService = $nseService;
}
public function index()
{
//return $this->nsaService->getAllBillPayments();
return BillPaymentsResource::collection($this->nsaService->getAllBillPayments());
}
public function show($transactionId)
{
$billpayments = $this->nseService->getBillPaymentsByTransactionId($transactionId);
return new BillPaymentsResource($billpayments);
}
}
Criador
Leandro Ozorio
##########################
# Router
Route::get('nse/billpayments', 'NseController@index');
Route::get('nse/billpayments/{transactionId}', 'NseController@show');
Criador
Leandro Ozorio
##########################
# Resource
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class BillPaymentsResource extends JsonResource
{
public function toArray($request)
{
return [
'transactionId' => $this->transactionId,
'assignor' => $this->assignor,
'digitable' => $this->digitable,
'totalUpdated' => $this->totalUpdated,
'status' => $this->status,
// 'date' => Carbon::parse($this->created_at)->format('d/m/Y'),
];
}
}
Criador
Leandro Ozorio
##########################
# RepositoryServiceProvider
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Repositories\Contracts\{
NseRepositoryInterface
};
use App\Repositories\{
NseRepository
};
class RepositoryServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->bind(
NseRepositoryInterface::class,
NseRepository::class
);
}
public function boot()
{
}
}
Criador
Leandro Ozorio
##########################
# config/app.php - providers
App\Providers\RepositoryServiceProvider::class,
Criador
Leandro Ozorio
##########################
# NseRepositoryInterface
namespace App\Repositories\Contracts;
interface NseRepositoryInterface
{
public function getAllBillPayments();
public function getBillPaymentsByTransactionId(string $transactionId);
}
Criador
Leandro Ozorio
##########################
# NseRepository
namespace App\Repositories;
use App\Models\Nbexpress;
use App\Repositories\Contracts\NseRepositoryInterface;
class NseRepository implements NseRepositoryInterface
{
protected $entity;
public function __construct(Nbexpress $Nbexpress)
{
$this->entity = $Nbexpress;
}
public function getAllBillPayments()
{
return $this->entity->all();
}
public function getBillPaymentsByTransactionId(string $transactionId)
{
return $this->entity
->where('transactionId', $transactionId)
->first();
}
}
Criador
Leandro Ozorio
##########################
# NseService
namespace App\Services;
use App\Repositories\Contracts\NseRepositoryInterface;
class NseService
{
private $repository;
public function __construct(NseRepositoryInterface $repository)
{
$this->repository = $repository;
}
public function getAllBillPayments()
{
return $this->repository->getAllBillPayments();
}
public function getBillPaymentsByTransactionId($transactionId)
{
return $this->repository->getBillPaymentsByTransactionId($transactionId);
}
}
Criador
Leandro Ozorio
Error
Manager
Carlos Ferreira
Aquele erro no método "getTenantByUuid" foi resolvido?
Pergunto, porque no código não tem esse método, nem a chamada dele em local algum.
Tem esse código no GitHub?
Se sim, compartilha comigo, porque a leitura fica mais fácil.
Precisa estar logado para conseguir responder a este ticket!
Clique Aqui Para Entrar!