如何在laravel中对连接表进行选择查询?

时间:2018-05-24 00:39:37

标签: php sql laravel-5

我有用户和员工表。我想在登录后显示员工详细信息。工作人员显示将列出与登录用户具有相同部分的员工。例如,如果Adam(section / seksyen = A)登录,则显示的工作人员列表是A部分的工作人员。

如何在laravel中查询?

表用户:

   (import javax.swing.*)
    (import java.awt.*)
    (import java.awt.event.*)

    ;; Don't clear defglobals on (reset)
    (set-reset-globals FALSE)

    (defglobal ?*crlf* = "
    ")

    ;; Question and answer templates

    (deftemplate questions
        (slot ident)
        (slot type)
        (slot texte)
        (multislot valid))

    (deftemplate reponses
        (slot texte)
        (slot ident))
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; Module app-rules

    (defmodule interview) 

    (defrule MAIN::questions_basique_1
        (declare (auto-focus TRUE))
     =>
     (assert (ask age)))

    (defrule MAIN::questions_basique_2
        (declare (auto-focus TRUE))
     =>
     (assert (ask poids)))

    (defrule MAIN::questions_basique_3
        (declare (auto-focus TRUE))
     =>
     (assert (ask symptome_majeur_1))) 

    (defrule MAIN::questions_basique_4
        (declare (auto-focus TRUE))
     =>
     (assert (ask symptome_majeur_1)))

    ;; Engine rules
    ;;questions pour le corps etrangé
    (defrule MAIN::request-dyspné_oui
     ;; si le patient a une dyspnée
     (reponses (ident symptome_majeur_1) (texte ?i&:(eq (str-compare ?i yes)0)))
     =>
     ;;lui posée la question si elle est brute
     (assert (ask dypnée_brute)))

     (defrule MAIN::request-dyspné_brute_oui
      (declare (auto-focus TRUE))
     ;; si le patient a une dyspnée brute
     (reponses (ident dypnée_brute) (texte ?i&:(eq (str-compare ?i yes)0)))
     =>
     ;;poser la question sur syndrome de penetration
     (assert (ask syndrome_penetration)))

    (defrule MAIN::request-syndrome_penetration_oui
     (declare (auto-focus TRUE))
     ;; si le patient a eu syndrome de pénétration
     (reponses (ident syndrome_penetration) (texte ?i&:(eq (str-compare ?i yes)0)))
     =>
     ;;poser la quetion sur des rales sibilants unilatérauxé
     (assert (ask rales_sibilant_uni)))

    (defrule MAIN::request-rales_sibilant_uni_oui
     (declare (auto-focus TRUE))
     ;; s'il a des rales sibilants unilatéreaux
     (reponses (ident rales_sibilant_uni) (texte ?i&:(eq (str-compare ?i yes)0)))
     =>
     ;;faire une radio du thorax pour définir s'il ya difference de clarté
     (assert (ask Rx_diff_clarte)))

    (defrule MAIN::request-Rx_diff_clarte_oui
     (declare (auto-focus TRUE))
     ;; s'il a des differences de clarté
     (reponses (ident Rx_diff_clarte) (texte ?i&:(eq (str-compare ?i yes)0)))
     =>
     ;;faire une bronchoscopie
     (assert (ask Bronchioscopie)))

    ;; fin de l'interview

    ;;début du diagnostique    
    (defrule MAIN::Corps-etrange
       (declare (auto-focus TRUE))
       (MAIN::reponses(ident dypnée_brute)(texte yes))
       (MAIN::reponses(ident syndrome_penetration)(texte yes))
       (MAIN::reponses(ident rales_sibilant_uni)(texte yes))
       (MAIN::reponses(ident Rx_diff_clarte)(texte yes))
       (MAIN::reponses(ident Bronchioscopie)(texte yes))
        => 
        (assert recommend-action "Corps etrangé")(halt))

    ;; Results output

    (deffunction recommend-action (?action)
      "Give final instructions to the user"
      (call JOptionPane showMessageDialog ?*frame*
            (str-cat "I recommend that you " ?action)
            "Recommendation"
            (get-member JOptionPane INFORMATION_MESSAGE)))

    (defadvice before halt (?*qfield* setText "Close window to exit"))

    ;; Module ask

    (defmodule ask)
    ;;poser une question et retourner une reponse
    (deffunction ask-patient (?question ?type ?valid)
     "Set up the GUI to ask a question"
     (?*qfield* setText ?question)
     (?*apanel* removeAll)
     (if (eq ?type multi) then
     (?*apanel* add ?*acombo*)
     (?*apanel* add ?*acombo-ok*)
     (?*acombo* removeAllItems)
     (foreach ?item ?valid
     (?*acombo* addItem ?item))
     else
     (?*apanel* add ?*afield*)
     (?*apanel* add ?*afield-ok*)
     (?*afield* setText ""))
     (?*frame* validate)
     (?*frame* repaint))

    ;;vérifier si la reponse est bien oui ou non
    (deffunction is-of-type (?answer ?type ?valid)
      "Check that the answer has the right form"
      (if (eq ?type multi) then
        (foreach ?item ?valid
                 (if (eq (sym-cat ?answer) (sym-cat ?item)) then
                   (return TRUE)))
        (return FALSE))

      (if (eq ?type number) then
        (return (is-a-number ?answer)))

      ;; plain text
      (return (> (str-length ?answer) 0)))

    (deffunction is-a-number (?value)
      (try
       (integer ?value)
       (return TRUE)
       catch 
       (return FALSE)))

    (defrule ask::ask-question-by-id
     "Given the identifier of a question, ask it"
     (declare (auto-focus TRUE))
     (MAIN::questions (ident ?id) (texte ?text)
                      (type ?type)(valid $?valid))
     (not (MAIN::reponses (ident ?id)))
     (MAIN::ask ?id)
     =>
     (ask-patient ?text ?type ?valid)
     ((engine) waitForActivations))

    (defrule ask::collect-user-input
     "Check and optionally return an answer from the GUI"
     (declare (auto-focus TRUE))
     (MAIN::questions (ident ?id) (texte ?text) (type ?type)(valid ?valid))
     (not (MAIN::reponses (ident ?id)))
     ?user <- (user-input ?input)
     ?ask <- (MAIN::ask ?id)
     =>
     (if (is-of-type ?input ?type ?valid) then
     (assert (MAIN::reponses (ident ?id) (texte ?input)))
     (retract ?ask ?user)
     (return)
     else
     (retract ?ask ?user)
     (assert (MAIN::ask ?id))))

    ;; Main window
    (defglobal ?*frame* = (new JFrame "Assistant Diagnostique en pneumonie pédiatrique"))
    (?*frame* setDefaultCloseOperation (get-member JFrame EXIT_ON_CLOSE))
    (?*frame* setSize 700 700)
    (?*frame* setVisible TRUE)

    ;; Question field
    (defglobal ?*qfield* = (new JTextArea 5 40))
    (bind ?scroll (new JScrollPane ?*qfield*))
    ((?*frame* getContentPane) add ?scroll)
    (?*qfield* setText "Please wait...")

    ;; Answer area
    (defglobal ?*apanel* = (new JPanel))
    (defglobal ?*afield* = (new JTextField 40))
    (defglobal ?*afield-ok* = (new JButton OK))

    (defglobal ?*acombo* = (new JComboBox (create$ "yes" "no")))
    (defglobal ?*acombo-ok* = (new JButton OK))

    (?*apanel* add ?*afield*)
    (?*apanel* add ?*afield-ok*)
    ((?*frame* getContentPane) add ?*apanel* (get-member BorderLayout SOUTH))
    (?*frame* validate)
    (?*frame* repaint)

    (deffunction read-input (?EVENT)
      "An event handler for the user input field"
      (assert (ask::user-input (sym-cat (?*afield* getText)))))

    (bind ?handler (new jess.awt.ActionListener read-input (engine)))
    (?*afield* addActionListener ?handler)
    (?*afield-ok* addActionListener ?handler)

    (deffunction combo-input (?EVENT)
      "An event handler for the combo box"
      (assert (ask::user-input (sym-cat (?*acombo* getSelectedItem)))))

    (bind ?handler (new jess.awt.ActionListener combo-input (engine)))
    (?*acombo-ok* addActionListener ?handler)

    (deffacts MAIN::question-data

     "questions posée par le systeme"
     (questions (ident poids) (type number)(texte "quel poids a-t-il?")(valid))
     (questions (ident age) (type number)(texte "quelle age a l'enfant?")(valid))
     (questions (ident symptome_majeur_1) (type multi)(texte "presente t-il des dyspnées sifflantes?")(valid yes no))
     (questions (ident symptome_majeur_2) (type multi)(texte "presente t-il une toux chronique?")(valid yes no))
     (questions (ident dypnée_brute) (type multi)(texte "la dyspnée est-elle brusque?")(valid yes no))
     (questions (ident rale_sibilant) (type multi)(texte "a-t-il des rales sibilants?")(valid yes no))
     (questions (ident syndrome_penetration) (type multi)(texte "y a t-il eu syndrome de pénétration?")(valid yes no))
     (questions (ident rales_sibilant_uni) (type multi)(texte "a t-il/elle des rales sibilants unilatéraux?")(valid yes no)) 
     (questions (ident Rx_diff_clarte) (type multi)(texte "la radio du thorax presente t-elle une difference de clarté des deux champs pulmonaires?")(valid yes no))
     (questions (ident Bronchioscopie) (type multi)(texte "la Bronchioscopie montre t-elle un corps étrangé?")(valid yes no))
        (ask poids))

    (reset)
    (run-until-halt)
表工作人员:

  public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->string('password');
        $table->rememberToken();
        $table->timestamps();
        $table->string('section');
        $table->string('type');
    });
}

我已尝试过此查询,但无法正常工作。

 public function up()
{
    Schema::create('staffs', function (Blueprint $table) {
        $table->increments('id');
        $table->timestamps();
        $table->string('nama');
        $table->string('emel')->unique();
        $table->string('seksyen');
        $table->string('jawatan');
        $table->string('alamat');
        $table->string('no kakitangan');
    });

1 个答案:

答案 0 :(得分:0)

提取用户登录名称的正确代码是:

        $section = Auth::user()->section;

        $data['data'] = DB::table('staffs')->where('section','=', $section)->get();