Skip to content
This repository has been archived by the owner on Feb 16, 2022. It is now read-only.

How to get the query executed in Laravel 5.3 ? #165

Open
moschel26 opened this issue Oct 29, 2017 · 0 comments
Open

How to get the query executed in Laravel 5.3 ? #165

moschel26 opened this issue Oct 29, 2017 · 0 comments

Comments

@moschel26
Copy link

moschel26 commented Oct 29, 2017

My service to delete product id like this :

<?php
...
use App\Repositories\ProductRepository;
class ProductService
{
    private $product_repository;
    public function __construct(ProductRepository $product_repository)
    {
        $this->product_repository = $product_repository;
    }

    public function destroy($id)
    {
        DB::enableQueryLog();
        # your laravel query builder goes here
        $result = $this->product_repository->delete($id);
        $laQuery = DB::getQueryLog();
        $lcWhatYouWant = $laQuery[0]['query']; # <-------
        dd($lcWhatYouWant);
        # optionally disable the query log:
        DB::disableQueryLog();
    }
}

My repository like this :

<?php
...
use App\Models\Product;
use Illuminate\Contracts\Container\Container;
use Rinvex\Repository\Repositories\EloquentRepository;
class ProductRepository extends EloquentRepository
{
    public function __construct(Container $container)
    {
        $this->setContainer($container)
             ->setModel(Product::class)
             ->setRepositoryId('rinvex.repository.uniqueid');
    }
}

On the service, I try like that. I want to debug the query to get the error. But there is no error

The result of dd($lcWhatYouWant); not display

How to get the query executed?

I get reference to debug the query from here : https://stackoverflow.com/questions/27753868/how-to-get-the-query-executed-in-laravel-5-dbgetquerylog-returning-empty-arr

I try like that, but it does not work

Seems the debug query on this repository is different

@Omranic, Seems you can help me

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

No branches or pull requests

1 participant