想要在OctoberCMS中实现SimpleTree

时间:2018-10-23 11:21:24

标签: php laravel tree relation octobercms

我想在OctoberCMS中实现父子关系。我有两个模型客户端和会话。这是一对多的关系。一个客户端有多个会话。我的目标是在单击客户端列表行时,它将展开会话子行。这是我的模型的代码-

客户端模型

<?php 
namespace Smriad\Pracitioner\Models;

use Model;


class Client extends Model
{
    use \October\Rain\Database\Traits\Validation;
    use \October\Rain\Database\Traits\SimpleTree;


    public $timestamps = false;

    /**
     * @var array Validation rules
     */
    public $rules = [
    ];

    /**
     * @var string The database table used by the model.
     */
    public $table = 'smriad_pracitioner_client';

    public $hasMany = [
        'session' => ['Smriad\Pracitioner\Models\Session', 'key' => 'client_id']
        // ^ you can use house instead houses for relation name
    ];
}

会话模型

<?php namespace Smriad\Pracitioner\Models;

use Model;

/**
 * Model
 */
class Session extends Model
{
    use \October\Rain\Database\Traits\Validation;

    use \October\Rain\Database\Traits\SimpleTree;
    /*
     * Disable timestamps by default.
     * Remove this line if timestamps are defined in the database table.
     */
    public $timestamps = false;

    /**
     * @var array Validation rules
     */
    public $rules = [
    ];

    /**
     * @var string The database table used by the model.
     */
    public $table = 'smriad_pracitioner_client_session';

    public $belongsTo = [
        'client' => ['Smriad\Pracitioner\Models\Client', 'key' => 'client_id']
        // ^ you can use house instead houses for relation name
    ];
}

0 个答案:

没有答案