我有两个表格,一个用于“模型”,另一个用于“投票”,我想通过投票获得模型名称(投票字段=模型ID)投票迁移表public function up(){ Schema::create('votantes', function (Blueprint $table) { $table->increments('id'); $table->string('nome', 100); $table->string('email', 60)->unique(); $table->integer('voto')->unsigned(); $table->timestamps(); $table->foreign('voto')->references('id')->on('candidatas')->onDelete('restrict'); });}投票模型<?phpnamespace App;use Illuminate\Database\Eloquent\Model;use App\Candidata;class Votante extends Model{ protected $fillable = ['nome', 'email', 'voto']; public function candidata() { return $this->belongsTo('App\Candidata'); }}型号迁移表public function up(){ Schema::create('candidatas', function (Blueprint $table) { $table->increments('id'); $table->string('nome', 100); $table->string('clube', 60); $table->string('foto', 100); $table->timestamps(); });}我的控制器public function votacao(){ $linhas = Votante::orderBy('nome')->get(); // dd($linhas); return view('votacao', ['linhas' => $linhas]);}我要在其中显示投票成员,电子邮件和model_name的刀片文件<table class="table table-hover"> <thead> <tr> <th>Cód Votante</th> <th>Nome Votante</th> <th>Modelo Escolhida(Cód)</th> <th>e-mail</th> </tr> </thead> @foreach ($linhas as $linha) <tr> <td> {{ $linha->id }} </td> <td> {{ $linha->nome }} </td> <td> {{ $linha->candidata->nome }} </td> <td> {{ $linha->email }} </td> @endforeach我要记录投票项,并从该数据在另一个窗口中显示投票者的姓名,电子邮件和模型的名称。当前整个列表工作正常,唯一的障碍是显示模板的名称,而不是在投票表中注册的“ id”。
- 2 回答
- 0 关注
- 195 浏览
添加回答
举报
0/150
提交
取消