Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 8数据表加载不工作(Yajra)_Php_Laravel_Laravel Blade_Yajra Datatable - Fatal编程技术网

Php Laravel 8数据表加载不工作(Yajra)

Php Laravel 8数据表加载不工作(Yajra),php,laravel,laravel-blade,yajra-datatable,Php,Laravel,Laravel Blade,Yajra Datatable,我正在使用Yajra Datatables来获取表中的数据 我需要显示表认证机构的数据,其中所述表的非官方类别id列应显示另一个数据库表非官方类别的区域名称 以下是认证机构模型,显示其与非官方类别模型的关系: <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Da

我正在使用Yajra Datatables来获取表中的数据

我需要显示表
认证机构的数据,其中所述表的
非官方类别id
列应显示另一个数据库表
非官方类别的
区域名称

以下是
认证机构
模型,显示其与
非官方类别
模型的关系:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Accreditors extends Model
{
    use HasFactory;
    use SoftDeletes;

    protected $table = "accreditors";

    protected $fillable = [
        'name',
        'official_category_id',
        'subcategory',
        'position',
        'photo',
    ];

    protected $dates = [
        'deleted_at',
        'created_at',
        'updated_at'
    ];

    public function nonOfficialsCategories()
    {
        return $this->belongsTo(NonOfficialsCategories::class, 'nonofficial_category_id');
    }
}
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class NonOfficialsCategories extends Model
{
    use HasFactory;
    use SoftDeletes;

    protected $table = "non_officials_categories";

    protected $fillable = [
        'area_number',
        'area_name',
        'subcategory',
        'is_accreditor_head',
        'is_taskforce_head',
        'is_auditor',
        'use_counter',
    ];

    protected $dates = [
        'deleted_at',
        'created_at',
        'updated_at'
    ];

    public function taskforces()
    {
        return $this->has(TaskForces::class);
    }
    public function accreditors()
    {
        return $this->has(Accreditors::class);
    }
}
以下是
非官方类别
模型,显示了其与
认证机构的关系
模型:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Accreditors extends Model
{
    use HasFactory;
    use SoftDeletes;

    protected $table = "accreditors";

    protected $fillable = [
        'name',
        'official_category_id',
        'subcategory',
        'position',
        'photo',
    ];

    protected $dates = [
        'deleted_at',
        'created_at',
        'updated_at'
    ];

    public function nonOfficialsCategories()
    {
        return $this->belongsTo(NonOfficialsCategories::class, 'nonofficial_category_id');
    }
}
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class NonOfficialsCategories extends Model
{
    use HasFactory;
    use SoftDeletes;

    protected $table = "non_officials_categories";

    protected $fillable = [
        'area_number',
        'area_name',
        'subcategory',
        'is_accreditor_head',
        'is_taskforce_head',
        'is_auditor',
        'use_counter',
    ];

    protected $dates = [
        'deleted_at',
        'created_at',
        'updated_at'
    ];

    public function taskforces()
    {
        return $this->has(TaskForces::class);
    }
    public function accreditors()
    {
        return $this->has(Accreditors::class);
    }
}
以下是数据表的当前(和错误)显示:

__________________________________________________________________________
|name     |area name        |subcategory     |position      |actions     |
__________________________________________________________________________
|         |1 //wrong        |                |              |            |
__________________________________________________________________________
|         |2 //wrong        |                |              |            |
__________________________________________________________________________
|         |3 //wrong        |                |              |            |
__________________________________________________________________________
其中,显示器应为:

__________________________________________________________________________
|name     |area name        |subcategory     |position      |actions     |
__________________________________________________________________________
|         |Area I //right   |                |              |            |
__________________________________________________________________________
|         |Area II //right  |                |              |            |
__________________________________________________________________________
|         |Area III //right |                |              |            |
__________________________________________________________________________
我的错误可能是:

  • 模型文件的雄辩关系错误
  • 脚本
    部分的
    数组中的
    .blade
    部分的语法声明错误
  • 对于
    AuthoritorsController
    ,在
    indexDatatables
    方法上的语法声明错误

谢谢。

在检查我的错误后,我找到了解决办法

我需要在
indexDatatables()
上添加另一个
addColumn()
API:

然后我可以在
.blade
文件的
脚本部分使用以下行:

// format {data: 'name_parameter_in_add_column', name: 'relationshipName.column_name_to_be_searched'},

{data: 'area_name', name: 'nonOfficialsCategories.nonofficial_category_id'},

// the 'area_name' in the script section should be the same name declared in the first parameter of the "addColumn()" API

现在,我仍然可能在关系声明上出错,因为我仍然对
belongsTo()/belongsToMany()
API的用法感到困惑。如果有人能纠正我,我将不胜感激

// format {data: 'name_parameter_in_add_column', name: 'relationshipName.column_name_to_be_searched'},

{data: 'area_name', name: 'nonOfficialsCategories.nonofficial_category_id'},

// the 'area_name' in the script section should be the same name declared in the first parameter of the "addColumn()" API