首页 > 解决方案 > 如何使用 Laravel 在同一个模型中编写两个表?

问题描述

我想在同一模型中创建另一个包含其他列的表。这可能吗?

这是我的模型

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
class Tbl_Perimetro extends Model
{
protected $table = "tbl_perimetros";
protected $fillable = [
'id', 'rif', 'act', 'razon_social', 'holdings_id', 'tipo', 'facturando', 'pines_id', 'regionduenas_id', 'sectoreconomicos_id', 'segmentos_id', 'segmentacionatcs_id', 'segmentacionings_id', 'estatus', 'equipos_id', 'ing', 'cobranzas_id', 'comerciales_id', 'ingpreventa_id', 'ingproyectos_id', 'postventaatc_id', 'postventaing_id'
];
protected $guarded = ['id'];
}

标签: laraveleloquent

解决方案


首先我应该说每个模型都是为一个特定的表编写的,除非它们是相关的,否则你不能将两个表压缩到一个模型中。看这里


推荐阅读