使用laravel 4.2中列表(查询构建器)内的连接查询中的数据

时间:2015-10-16 07:45:00

标签: php laravel laravel-4

嗨我是laravel的新手,而不是程序员,所以我在我的控制器中有这个代码,我希望得到基于数据库记录的结果集,然后使用它作为我的视图下拉列表的选择这里是我的代码在我的控制器中

Private Sub Worksheet_Activate()

Dim Home As Worksheet
Set Home = Worksheets("Program Status Summary")
Home.Range("A1").Value = Format(Now(), "dd/mmm/yyyy")

End Sub

我试图让下拉列表看起来像例如:

ID | 1 |比利|乔| 12345

有更好的方法吗?非常感谢

1 个答案:

答案 0 :(得分:2)

您应该在Sub combinations() Dim i As Long, j As Long, k As Long, l As Long, n As Long, m As Long, lr As Long With ActiveSheet lr = .Cells(Rows.Count, 1).End(xlUp).Row For i = 2 To lr For j = i + 1 To lr For k = j + 1 To lr For l = k + 1 To lr For n = l + 1 To lr For m = n + 1 To lr .Cells(Rows.Count, 6).End(xlUp).Offset(1, 0) = .Cells(i, 1).Value & " " & .Cells(j, 1).Value & " " & .Cells(k, 1).Value & " " & .Cells(l, 1).Value & " " & .Cells(n, 1).Value & " " & .Cells(m, 1).Value Next m Next n Next l Next k Next j Next i End With End Sub Student模型之间建立关系。

学生模特(App \ Student.php):

StudentRecord

StudentRecord模型(App \ StudentRecord.php):

class Student extends Model {

    protected $table = 'students';

    public function StudentRecord() {
        return $this->hasOne('App\StudentRecord');
    }

}

如果您创建了关系(一对一),则可以在Controller中使用以下查询:

class StudentRecord extends Model {

    protected $table = 'student_records';

    public function Student() {
        return $this->belongsTo('App\Student');
    }

}

You can read about the load() function.