Bonjour,

J'ai un modèle cahier_charge et un modèle signe_qualite avec une relation 1,n entre les deux.

J'utilise Datatables pour afficher les données cahier_charge.
J'aimerais afficher LIBELLE_SIGNE_QUALITE, mais ça affiche la clé ID_SIGNE_QUALITE.

Je ne vois comment faire pour afficher le libellé et pas la clé.

La classe CahierChargeDataTable
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
 
namespace App\DataTables;
 
use App\Models\CahierCharge;
use Yajra\DataTables\Services\DataTable;
use Yajra\DataTables\EloquentDataTable;
use Yajra\DataTables\Html\Column;
 
class CahierChargeDataTable extends DataTable
{
    /**
     * Build DataTable class.
     *
     * @param mixed $query Results from query() method.
     * @return \Yajra\DataTables\DataTableAbstract
     */
    public function dataTable($query)
    {
        $dataTable = new EloquentDataTable($query);
 
        return $dataTable->addColumn('action', 'cahier_charges.datatables_actions');
    }
 
    /**
     * Get query source of dataTable.
     *
     * @param \App\Models\CahierCharge $model
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function query(CahierCharge $model)
    {
        return $model->newQuery();
 
    }
 
    /**
     * Optional method if you want to use html builder.
     *
     * @return \Yajra\DataTables\Html\Builder
     */
    public function html()
    {
        return $this->builder()
            ->columns($this->getColumns())
            ->minifiedAjax()
            ->addAction(['width' => '120px', 'printable' => false, 'title' => __('crud.action')])
            ->parameters([
                'dom'       => 'Bfrtip',
                'stateSave' => true,
                'order'     => [[0, 'desc']],
                'buttons'   => [
                    [
                       'extend' => 'create',
                       'className' => 'btn-primary-table btn btn-default btn-sm no-corner',
                       'text' => '<i class="fa fa-plus"></i> ' .__('auth.app.create').''
                    ],
                    [
                       'extend' => 'export',
                       'className' => 'btn-primary-table btn btn-default btn-sm no-corner',
                       'text' => '<i class="fa fa-download"></i> ' .__('auth.app.export').''
                    ],
                    [
                       'extend' => 'print',
                       'className' => 'btn-primary-table btn btn-default btn-sm no-corner',
                       'text' => '<i class="fa fa-print"></i> ' .__('auth.app.print').''
                    ],
                    [
                       'extend' => 'reset',
                       'className' => 'btn-primary-table btn btn-default btn-sm no-corner',
                       'text' => '<i class="fa fa-undo"></i> ' .__('auth.app.reset').''
                    ],
                    [
                       'extend' => 'reload',
                       'className' => 'btn-primary-table btn btn-default btn-sm no-corner',
                       'text' => '<i class="fa fa-refresh"></i> ' .__('auth.app.reload').''
                    ],
                ],
                 'language' => [
                   'url' => url('../resources/lang/fr/DataTables/French.json'),
                 ],
            ]);
    }
 
    /**
     * Get columns.
     *
     * @return array
     */
    protected function getColumns()
    {
        return [
            'LIBELLE_CAHIER_CHARGE' => new Column(['title' => __('models/cahierCharges.fields.LIBELLE_CAHIER_CHARGE'), 'data' => 'LIBELLE_CAHIER_CHARGE']),
            'ID_SIGNE_QUALITE' => new Column(['title' => __('models/cahierCharges.fields.ID_SIGNE_QUALITE'), 'data' => 'ID_SIGNE_QUALITE']),
            'DATE_CAHIER_CHARGE' => new Column(['title' => __('models/cahierCharges.fields.DATE_CAHIER_CHARGE'), 'data' => 'DATE_CAHIER_CHARGE']),
            'FICHIER_CAHIER_CHARGE' => new Column(['title' => __('models/cahierCharges.fields.FICHIER_CAHIER_CHARGE'), 'data' => 'FICHIER_CAHIER_CHARGE'])
        ];
    }
 
    /**
     * Get filename for export.
     *
     * @return string
     */
    protected function filename()
    {
        return 'cahier_chargesdatatable_' . time();
    }
}

Le modèle CahierCharge
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
 
namespace App\Models;
 
use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;
 
/**
 * Class CahierCharge
 * @package App\Models
 * @version April 22, 2020, 6:57 am UTC
 *
 * @property \App\Models\SigneQualite idSigneQualite
 * @property \App\Models\EstConforme estConforme
 * @property integer ID_SIGNE_QUALITE
 * @property string DATE_CAHIER_CHARGE
 * @property string LIBELLE_CAHIER_CHARGE
 * @property string FICHIER_CAHIER_CHARGE
 */
class CahierCharge extends Model
{
    use SoftDeletes;
 
    public $table = 'cahier_charge';
 
    const CREATED_AT = 'created_at';
    const UPDATED_AT = 'updated_at';
 
 
    protected $dates = ['deleted_at'];
 
 
    protected $primaryKey = 'ID_CAHIER_CHARGE';
 
    public $fillable = [
        'ID_SIGNE_QUALITE',
        'DATE_CAHIER_CHARGE',
        'LIBELLE_CAHIER_CHARGE',
        'FICHIER_CAHIER_CHARGE'
    ];
 
    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'ID_CAHIER_CHARGE' => 'integer',
        'ID_SIGNE_QUALITE' => 'integer',
        'DATE_CAHIER_CHARGE' => 'string',
        'LIBELLE_CAHIER_CHARGE' => 'string',
        'FICHIER_CAHIER_CHARGE' => 'string'
    ];
 
    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        'LIBELLE_CAHIER_CHARGE' => 'required'
    ];
 
    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     **/
    public function idSigneQualite()
    {
        return $this->belongsTo(\App\Models\SigneQualite::class, 'ID_SIGNE_QUALITE');
    }
 
}
Nom : Capture.PNG
Affichages : 410
Taille : 9,6 Ko