我有兩個表格,一個用于“模型”,另一個用于“投票”,我想通過投票獲得模型名稱(投票字段=模型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我要記錄投票項,并從該數(shù)據(jù)在另一個窗口中顯示投票者的姓名,電子郵件和模型的名稱。當(dāng)前整個列表工作正常,唯一的障礙是顯示模板的名稱,而不是在投票表中注冊的“ id”。
- 2 回答
- 0 關(guān)注
- 211 瀏覽
添加回答
舉報
0/150
提交
取消