Matthew B
asked on
Where to store my raw queries for Laravel Project?
I have some complex queries with many joins i am using in a laravel project.
Currently all queries are in my controller which i want to refactor into a App\Queries namespace.
I am stuck on the app flow, would i call these queries from my model, or my controller directly?
would this be a correct structure?
then how would i call this query from my controller/model?
does this make sense ? am i way off?
Currently all queries are in my controller which i want to refactor into a App\Queries namespace.
I am stuck on the app flow, would i call these queries from my model, or my controller directly?
would this be a correct structure?
<?php
namespace App\Queries;
//App\Queries\GetClient;
class Client {
public function get($cID){
$client = DB::select( DB::raw("
select
client_id,
client_name,
client_phone,
client_address
from clients
where client_id = :cID"
), array("cID" => $cID));
return $client;
}
}
then how would i call this query from my controller/model?
<?PHP
//call from model ??
//call directly from controller??
public function show(Request $cID){
$client = new App\Queries\GetClient->get();
//return to view or what ever
}
does this make sense ? am i way off?
That looks fine, have you tried it?
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.