lundi 30 octobre 2023

Get query results even with null foreign key

I have a query in which I have multiple relationships.

The foreign key 'acquirente_corretor_id' can be null or not. If it is different from null, it has a relationship with the dobby table.

I have the following query, but it only works for 'acquirente_corretor_id' that is not null. Only displays the result with this key other than null.

I want it to show the result of 'acquirente_corretor_id' even though it is null, merging.

One more thing, you only query the acquirer relationship if the variables $empresa_recebedora, $acquirente, $serial are different from null.

How to make? I've tried different forms of querying and it doesn't show.

$contratos = Contrato::with([
                    'parcela',
                    'cliente',
                    'status',
                    'operador',
                    'tabela',
                    'adquirente',
                    'bancos',
                    'bancos.empresa',
                    'bancos.banco',
                    'adquirente'
                ])
                    ->whereHas('cvs', function ($q) use ($cv) {
                        if (!is_null($cv)) {
                            $q->where('cv', $cv);
                        }
                    })
                    ->whereHas('bancos', function ($q) use ($banco, $empresa_pagadora) {
                        if (!is_null($banco)) {
                            $q->where('banco_id', $banco);
                        }
                        if (!is_null($empresa_pagadora)) {
                            $q->where('empresa_id', $empresa_pagadora);
                        }
                    })
                    ->whereHas('cliente', function ($q) use ($cliente) {
                        if (!is_null($cliente)) {
                            $q->where('nome', 'LIKE', "%{$cliente}%");
                        }
                    })
                    ->whereHas('adquirente.maquineta.empresa', function ($q) use ($empresa_recebedora) {
                        if (!is_null($empresa_recebedora)) {
                            $q->where('empresa_id', $empresa_recebedora);
                        }
                    })
                    ->whereHas('adquirente.maquineta.adquirente', function ($q) use ($adquirente) {
                        if (!is_null($adquirente)) {
                            $q->where('adquirente_id', $adquirente);
                        }
                    })
                    ->whereHas('adquirente.maquineta', function ($q) use ($serial) {
                        if (!is_null($serial)) {
                            $q->where('numero_serie', $serial);
                        }
                    })
                    ->when($status, function ($query, $status) {
                        $query->whereIn('contratos.status_id', $status);
                    })
                    ->when($ca, function ($query, $ca) {
                        $query->where('contratos.conciliacao_adquirente', $ca);
                    })
                    ->when($cb, function ($query, $cb) {
                        $query->where('contratos.conciliacao_bancaria', $cb);
                    })
                    ->when($operador, function ($query, $operador) {
                        $query->where('contratos.operador_id', $operador);
                    })
                    ->when($multiplicador, function ($query, $multiplicador) {
                        $query->where('contratos.multiplicador_id', $multiplicador);
                    })
                    ->when($gerente, function ($query, $gerente) {
                        $query->where('contratos.gerente_id', $gerente);
                    })
                    ->when($indicador, function ($query, $indicador) {
                        $query->where('contratos.indicador_id', $indicador);
                    })
                    ->when($valor_liquido, function ($query, $valor_liquido) {
                        $query->where('contratos.valor_liquido', 'LIKE', "{$valor_liquido}%");
                    })
                    ->where(function ($query) use ($inicio, $fim) {
                        if (!is_null($inicio) && !is_null($fim)) {
                            $query->whereBetween('data_operacao', [$inicio, $fim]);
                        }
                    })                    
                    ->orderBy($request->sortField, $sortOrder)
                    ->get()
                    ->each(function ($query) {
                        $pagadoras = $query->bancos;
                        foreach ($pagadoras as $pagadora) {
                            $empresas[] = $pagadora->empresa['nome'];
                            $bancos[] = $pagadora->banco['nome'];
                            $recebedores[] = $pagadora->cpf . ' - ' . $pagadora->nome;
                        }
        
                        $cvs = $query->cvs;
                        foreach ($cvs as $codigo) {
                            $codigos[] = $codigo->cv;
                        }
        
                        $query->empresas_pagadoras = implode(', ', $empresas);
                        $query->bancos_pagadores = implode(', ', $bancos);
                        $query->lista_codigos = implode(', ', $codigos);
                        $query->recebedores = implode(', ', $recebedores);
                    });

I tried solving it this way, but I get the following error:

Call to undefined method Illuminate\Database\Query\Builder::acquirente()

One more thing, you only query the acquirer relationship if the variables $empresa_recebedora, $acquirente, $serial are different from null

`$contratos = Contrato::with([ 'parcela', 'cliente', 'status', 'operador', 'tabela', 'bancos', 'bancos.empresa', 'bancos.banco', 'adquirente' ]) ->whereHas('cvs', function ($q) use ($cv) { if (!is_null($cv)) { $q->where('cv', $cv); } }) ->whereHas('bancos', function ($q) use ($banco, $empresa_pagadora) { if (!is_null($banco)) { $q->where('banco_id', $banco); } if (!is_null($empresa_pagadora)) { $q->where('empresa_id', $empresa_pagadora); } }) ->whereHas('cliente', function ($q) use ($cliente) { if (!is_null($cliente)) { $q->where('nome', 'LIKE', "%{$cliente}%"); } }) ->whereHas('adquirente', function ($q) use ($empresa_recebedora, $adquirente, $serial) { $q->whereHas('adquirente.maquineta.empresa', function ($q) use ($empresa_recebedora) { if (!is_null($empresa_recebedora)) { $q->where('empresa_id', $empresa_recebedora); } }) ->whereHas('adquirente.maquineta.adquirente', function ($q) use ($adquirente) { if (!is_null($adquirente)) { $q->where('adquirente_id', $adquirente); } }) ->whereHas('adquirente.maquineta', function ($q) use ($serial) { if (!is_null($serial)) { $q->where('numero_serie', $serial); } }); }) ->when($status, function ($query, $status) { $query->whereIn('contratos.status_id', $status); }) ->when($ca, function ($query, $ca) { $query->where('contratos.conciliacao_adquirente', $ca); }) ->when($cb, function ($query, $cb) { $query->where('contratos.conciliacao_bancaria', $cb); }) ->when($operador, function ($query, $operador) { $query->where('contratos.operador_id', $operador); }) ->when($multiplicador, function ($query, $multiplicador) { $query->where('contratos.multiplicador_id', $multiplicador); }) ->when($gerente, function ($query, $gerente) { $query->where('contratos.gerente_id', $gerente); }) ->when($indicador, function ($query, $indicador) { $query->where('contratos.indicador_id', $indicador); }) ->when($valor_liquido, function ($query, $valor_liquido) { $query->where('contratos.valor_liquido', 'LIKE', "{$valor_liquido}%"); }) ->where(function ($query) use ($inicio, $fim) { if (!is_null($inicio) && !is_null($fim)) { $query->whereBetween('data_operacao', [$inicio, $fim]); } }) ->orderBy($request->sortField, $sortOrder) ->get() ->each(function ($query) { $pagadoras = $query->bancos; foreach ($pagadoras as $pagadora) { $empresas[] = $pagadora->empresa['nome']; $bancos[] = $pagadora->banco['nome']; $recebedores[] = $pagadora->cpf . ' - ' . $pagadora->nome; }

            $cvs = $query->cvs;
            foreach ($cvs as $codigo) {
                $codigos[] = $codigo->cv;
            }

            $query->empresas_pagadoras = implode(', ', $empresas);
            $query->bancos_pagadores = implode(', ', $bancos);
            $query->lista_codigos = implode(', ', $codigos);
            $query->recebedores = implode(', ', $recebedores);
        });`


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/rFlsR37
via IFTTT

dimanche 29 octobre 2023

Unable to display data from database on a card using laravel

Even though there are many solutions provided for this error, I am encoutering, I have not find the solution yet, below is the error I am getting when trying to display data from the database on the bootstrap card ") ErrorException Undefined variable: published_articles (View: /home/nosi/Oresol-Lesotho-Skills-Exercise/blog/resources/views/article_data.blade.php) (View: /home/nosi/Oresol-Lesotho-Skills-Exercise/blog/resources/views/article_data.blade.php"

below is my route inside the web.php:

  Route::get('article_data', 'PublishArticlesController@retrieveArticles')->name('article_data');

below is my controller:

public function retrieveArticles(){

$articles = PublishArticle::latest()->paginate(6);
return view('article_data')->with(['published_articles'=>$articles]);

}

below is my blade file which is inside views, articles_data.blade.php:

    @extends('layouts.public_navbar')

@section('content')
<div class="container text-center">
    <h1>Explore Published Articles</h1>
</div>
<div class="container">
    <div class="card-deck row">
    @foreach ($published_articles as $article)
            <div class="col-xs-12 col-sm-6 col-md-4">
                <div class="card">
                    <div class="view overlay">
                        <a href="#!">
                            <div class="mask rgba-white-slight"></div>
                        </a>
                    </div>
                    <div class="card-body">
                        <h4 class="card-title"></h4>
                        <p>Author: </p>
                        <p class="card-text"></p>
                        <a href="" class="btn btn-primary btn-md">Read more</a>
                    </div>
                </div>
            </div>
        @endforeach
    </div>
</div>

<!-- Add Bootstrap JS and Popper.js scripts (required for Bootstrap) -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.3/dist/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
@endsection

your help will be highly apreciated



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/oc3eU1C
via IFTTT

samedi 28 octobre 2023

Laravel getting data from the database in .js file

I need to change the series values ​​in the .js file by pulling data from the database, how can I do this? @php not working in js file

_wChartTwo.28581ae9.js file:

window.addEventListener("load",function(){try{let s=sessionStorage.getItem("theme");if(JSON.parse(s).settings.layout.darkMode){var o="dark";Apex.tooltip={theme:o};var a={chart:{type:"donut",width:370,height:430},colors:["#622bd7","#e2a03f","#e7515a","#e2a03f"],dataLabels:{enabled:!1},legend:{position:"bottom",horizontalAlign:"center",fontSize:"14px",markers:{width:10,height:10,offsetX:-5,offsetY:0},itemMargin:{horizontal:10,vertical:30}},plotOptions:{pie:{donut:{size:"75%",background:"transparent",labels:{show:!0,name:{show:!0,fontSize:"29px",fontFamily:"Nunito, sans-serif",color:void 0,offsetY:-10},value:{show:!0,fontSize:"26px",fontFamily:"Nunito, sans-serif",color:"#1ad271",offsetY:16,formatter:function(t){return t}},total:{show:!0,showAlways:!0,label:"Total",color:"#888ea8",formatter:function(t){return t.globals.seriesTotals.reduce(function(n,e){return n+e},0)}}}}}},stroke:{show:!0,width:15,colors:"#0e1726"},series:[985,737,270],labels:["Apparel","Sports","Others"],responsive:[{breakpoint:1440,options:{chart:{width:325}}},{breakpoint:1199,options:{chart:{width:380}}},{breakpoint:575,options:{chart:{width:320}}}]}}else{var o="dark";Apex.tooltip={theme:o};var a={chart:{type:"donut",width:370,height:430},colors:["#622bd7","#e2a03f","#e7515a","#e2a03f"],dataLabels:{enabled:!1},legend:{position:"bottom",horizontalAlign:"center",fontSize:"14px",markers:{width:10,height:10,offsetX:-5,offsetY:0},itemMargin:{horizontal:10,vertical:30}},plotOptions:{pie:{donut:{size:"75%",background:"transparent",labels:{show:!0,name:{show:!0,fontSize:"29px",fontFamily:"Nunito, sans-serif",color:void 0,offsetY:-10},value:{show:!0,fontSize:"26px",fontFamily:"Nunito, sans-serif",color:"#0e1726",offsetY:16,formatter:function(e){return e}},total:{show:!0,showAlways:!0,label:"Total",color:"#888ea8",formatter:function(e){return e.globals.seriesTotals.reduce(function(i,l){return i+l},0)}}}}}},stroke:{show:!0,width:15,colors:"#fff"},series:[985,737,270],labels:["Apparel","Sports","Others"],responsive:[{breakpoint:1440,options:{chart:{width:325}}},{breakpoint:1199,options:{chart:{width:380}}},{breakpoint:575,options:{chart:{width:320}}}]}}var r=new ApexCharts(document.querySelector("#chart-2"),a);r.render(),document.querySelector(".theme-toggle").addEventListener("click",function(){let t=sessionStorage.getItem("theme");JSON.parse(t).settings.layout.darkMode?r.updateOptions({stroke:{colors:"#0e1726"},plotOptions:{pie:{donut:{labels:{value:{color:"#bfc9d4"}}}}}}):r.updateOptions({stroke:{colors:"#fff"},plotOptions:{pie:{donut:{labels:{value:{color:"#0e1726"}}}}}})})}catch(s){console.log(s)}});

analytics.blade file:

 <div class="col-xl-4 col-lg-12 col-md-12 col-sm-12 col-12 layout-spacing">
            <x-widgets._w-chart-two title="Sales by Category"/>
        </div>


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3XEg7Mt
via IFTTT

vendredi 27 octobre 2023

What is the optimised way to pull all items related to parent table from the mysql table?

Suppose we have a table of order consisting of order ids, what would be considered 'best practice' in terms of fetching all item data with their order?

Order table:
--------

| id | name | email |  phone | event_id |
|---- |------| -----|-----| -----|
| 1    | Anish  | anish@gmail.com | 8233472332| 1765 |
| 2    | ABC    | abc@gmail.com   | 784472332| 1765 |
| 3    | XYZ    | xyz@gmail.com   | 646322332| 1525 |

items table:
------------


| id | order_id | category |  qty | price |
|---- |------| -----|-----| -----|
| 1    | 1  | person 1 | 2| 299 |
| 2    | 1    | person 2   | 1| 399 |
| 3    | 2    | person 1   | 1| 299 |

I want to fetch all items and their order name, email, phone in a single query.

Expected result

| name | email | category |  qty | price |
|---- |------| -----------|----- | ----- |
|  Anish   | anish@gmail.com   | person 1 | 2| 299 |
| Anish    | anish@gmail.com.  | person 2   | 1| 399 |
| ABC      | abc@gmail.com     | person 1   | 1| 299 |

One to many relation Orders -> items (It has multiple rows related to a single order)

I want to display all items for an event along with name, email, and phone. Please suggest to me the optimized mysql query for the same. I am using laravel 5.2.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/z3nvA8k
via IFTTT

lundi 23 octobre 2023

I have error while i copy laravel project from shared hosting to local

I want to copy laravel from shared hosting into my computer and run it from xampp server this is my road:

  1. i'm compress public_html folder from host
  2. download it and extract in xampp/htacess/project_name directory
  3. i was export database from server and import in local phpmyadmin
  4. delete vender directory and run composer install
  5. edit config/database.php with my local database information
  6. edit .env file with local information after all i run php artisan serve and i get this error screenshot avilable up there does anybody can help me

enter image description here



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/K3CAumj
via IFTTT

vendredi 20 octobre 2023

socketlabs not working without plainTextBody

This is working fine but when I am sending without plainTextBody then its not working I need to use without plainTextBody, I need to set just subject and htmlBody .

When I am working without plainTextBody then its not working.

$message->subject = "Simple Html file with text";
$message->plainTextBody = "This is the Plain Text Body of my message.";
$message->from = new EmailAddress("from@example.com");
$message->addToAddress(new EmailAddress("recipient1@example.com", "Recipient #1"));

//Get html content from a file
$pathToHtmlFile = __DIR__ .'../../../ExampleCode/Html/SampleEmail.html'; 
$message->htmlBody = file_get_contents($pathToHtmlFile);
 
//Send the message
$response = $client->send($message);

I am using this one https://www.socketlabs.com/api/ but I do not want to use plainTextBody in our project.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/ANl2wmO
via IFTTT

lundi 16 octobre 2023

i tired search in google, GPT even Bard nothing change in this code, laravel 5 problem

so i have this code in laravel 5

Customer::where('type', 1)->join('tb_customer_connector', 'tb_contact.id_customer', '=', 'tb_customer_connector.id_customer')
        ->join('tb_technology_tag', 'tb_customer_connector.id_product', '=', 'tb_technology_tag.id')
        ->where('tb_technology_tag.about', $id)
        ->get();

and simply this code i use for make a tabbar that make a fillter based on the technology.about but if a customer have two technology with same about it will make the customer show duoble because duoble connector

duplicate customer image

i already use district and groupBy and other but nothing changes



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/rEZpuma
via IFTTT