requête SQL brute à laravel

Quelqu'un peut-il m'aider s'il vous plaît à écrire une version de requête DB de l'instruction SQL ci-dessous. J'ai besoin d'un peu d'aide autour de l'instruction select et des jointures partitionnées.

J'ai réussi à le faire jusqu'à présent.

$query = DB::table(raw('SapakInAdminOrder a')) ->select(raw('a.*')) ->leftJoin(raw('currency cu'), 'a.currency', '=', 'cu.id') ->leftJoin(raw('moodboards m'), 'a.orderMoodboardID', '=', 'm.id') ->join(raw('clients b'), 'a.clientID', '=', 'b.id') ->leftJoin(raw('moodboards mc'), 'b.moodboardID', 'mc.id') ->join(raw('sapakim c'), 'b.sapakID', '=', 'c.id') ->leftJoin(raw('sapakim sm'), 'c.managerid', '=', 'sm.id') ->leftJoin(raw('products p'), 'a.productKey', '=', 'p.id') ->where(function ($query) { $query->whereNull('a.isDeleted'); $query->orWhere('a.isDeleted', '!=', 1); }); 

Mais je dois y arriver.

 select * from (select ROW_NUMBER() OVER(ORDER BY case when (indesign.status=4 or indesign.statusdate is null) then getdate()+2 else indesign.statusdate end ASC) AS RowNum,a.* FROM sapakInAdminOrder a left join currency cu on cu.id=a.currency left join moodboards m on m.id=a.orderMoodboardID inner join Clients b on a.clientID=b.id left join moodboards mc on mc.id=b.moodboardID inner join Sapakim c on b.sapakID=c.id left join Sapakim sm on sm.id=c.managerid left join products p on p.id=a.productKey left join (select * from (select ROW_NUMBER() over(PARTITION BY orderID ORDER BY id DESC) r, * from orderCommunication ) f where r=1) chat on chat.orderId = a.id left join (select id,[status],orderid,approveSMSDate,coverImage,statusDate from (SELECT id,[status],statusDate,approveSMSDate,coverImage,orderid,ROW_NUMBER() OVER(PARTITION BY orderid ORDER BY id DESC) AS r FROM SapakimInAdminDesigns) f where r=1) indesign on a.id=indesign.orderid where (a.isDeleted is null or a.isDeleted != 1) and c.inAdminManagerID=(select id from sapakim where sapakguid='test') and c.sapakguid='test' and a.isFreeDesign=0 and a.transactionID = -1 and (a.designerPaid is null or a.designerPaid=0) and (chat.sentToPrinter is null and chat.sentToManager is null and chat.sentToDesigner is null) ) bb where RowNum>=1 and RowNum<31 ORDER BY RowNum asc 

Je peux faire les simples mais je ne peux pas vraiment envelopper ma tête autour des jointures partitionnées et de l'instruction select .

J'apprécierais vraiment une aide à ce sujet.

Merci d'avance.

    Je suis aussi coincé avec ce type de problème mais j'ai une solution et ça marche bien pour moi!

    utilisez DB :: unprepared () pour ce type de requête:

     $path = base_path() . "/storage/agency.sql"; $sql = file_get_contents($path); DB::unprepared(DB::raw($sql)); 

    Toutes les commands SQL dans Laravel sont préparées par défaut, mais parfois vous devez exécuter une command dans un mode non préparé, car certaines commands dans certaines bases de données ne peuvent pas être exécutées en mode préparé.

    Est-ce que c'est ce que vous vouliez dire?

     $result = DB::Select("select * from (select ROW_NUMBER() OVER(ORDER BY case when (indesign.status=4 or indesign.statusdate is null) then getdate()+2 else indesign.statusdate end ASC) AS RowNum,a.* FROM sapakInAdminOrder a left join currency cu on cu.id=a.currency left join moodboards m on m.id=a.orderMoodboardID inner join Clients b on a.clientID=b.id left join moodboards mc on mc.id=b.moodboardID inner join Sapakim c on b.sapakID=c.id left join Sapakim sm on sm.id=c.managerid left join products p on p.id=a.productKey left join (select * from (select ROW_NUMBER() over(PARTITION BY orderID ORDER BY id DESC) r, * from orderCommunication ) f where r=1) chat on chat.orderId = a.id left join (select id,[status],orderid,approveSMSDate,coverImage,statusDate from (SELECT id,[status],statusDate,approveSMSDate,coverImage,orderid,ROW_NUMBER() OVER(PARTITION BY orderid ORDER BY id DESC) AS r FROM SapakimInAdminDesigns) f where r=1) indesign on a.id=indesign.orderid where (a.isDeleted is null or a.isDeleted != 1) and c.inAdminManagerID=(select id from sapakim where sapakguid='test') and c.sapakguid='test' and a.isFreeDesign=0 and a.transactionID = -1 and (a.designerPaid is null or a.designerPaid=0) and (chat.sentToPrinter is null and chat.sentToManager is null and chat.sentToDesigner is null) ) bb where RowNum>=1 and RowNum<31 ORDER BY RowNum asc"); 

    Peut-être que vous devriez créer une vue de database pour ces requêtes partitionnées? Ensuite, vous pouvez join la vue depuis la database par la suite.

    Techniquement, ces fonctions analytiques ne sont généralement pas supscopes par les frameworks.

    Découvrez ce nouvel outil Laravel appelé Orator. Il vous permet simplement de coller du code SQL «hérité» et renvoie la syntaxe de DB Query Builder de Laravel.

    Laravel Orator News Article

    devise de conversion en ligne

    En supposant que vous voulez afficher cela sur le frontend, utilisez les relations avec le model éloquent, https://laravel.com/docs/master/eloquent-relationships#one-to-one

    Dans l'user du model, il y a une relation One to One appelée par la méthode phone (), si vous allez à la vue show qui suppose que je passe une variable user $ faites ce qui suit

     <?php dd($user->phone); ?> 

    Je pourrais manquer tout le sharepoint la question si vous ne voulez pas dire cela.