我是laravel的新人。请帮我解决这个问题,我打算这样做。
所以,就是这样。我想显示经过身份验证的用户未请求的游戏列表。因此,如果经过身份验证的用户请求了,例如:“dota 2”游戏。名称“dota 2”将不会显示在选项列表中,因为用户ID和游戏ID已记录在游戏表中。
这就是我所做的。
应用\游戏
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Game extends Model
{
protected $fillable = [
'user_id', 'games_id', 'username', 'password'
];
public function user()
{
return $this->belongsTo(User::class);
}
public function gamelist()
{
return $this->belongsTo(Gamelist::class);
}
public function scopeIncomplete($query)
{
return $query->where('completed', 0);
}
}
应用\游戏列表
namespace App;
use Illuminate\Database\Eloquent\Model;
class Gamelist extends Model
{
//
}
游戏桌迁移文件
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateGamesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('games', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->integer('games_id')->unsigned();
$table->string('username')->nullable();
$table->string('password')->nullable();
$table->boolean('completed')->default(false);
$table->timestamps();
});
Schema::table('games', function($table) {
$table->foreign('user_id')->references('id')->on('users');
$table->foreign('games_id')->references('id')->on('gamelists');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('games');
}
}
Create_Gamelist_table迁移文件
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateGamesListsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('gamelists', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('gameslist');
}
}
我想制作一个选择表格
<select>
<option>{{-- This will display the name of the games that authenticated user haven't create or requested by using the table relation above--}}</option>
</select>
我被困住了,无法找到解决方案..请帮助:)