Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.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视图中显示连接表中的数据_Php_Mysql_Laravel_Laravel Blade - Fatal编程技术网

Php 在Laravel视图中显示连接表中的数据

Php 在Laravel视图中显示连接表中的数据,php,mysql,laravel,laravel-blade,Php,Mysql,Laravel,Laravel Blade,我有一个学校项目的问题,该项目是一个网站,你可以获得有关视频游戏(名称,游戏封面和发布日期)的信息,如果你想以后玩游戏,或者即使你想添加你已经完成的游戏,只需将游戏添加到你的列表中,这是一个简单的库应用程序。为了将游戏添加到您的列表中,您需要进入游戏所在的页面,用一个简单的按钮将其添加到列表中 现在我恢复了应用程序的功能,让我解释一下该网站是如何工作的 这个网站是用Laravel6构建的,我想实现的所有功能都在运行,除了一个,在你的列表中添加一个游戏。添加一个游戏到你的列表是很好的数据库端,但我

我有一个学校项目的问题,该项目是一个网站,你可以获得有关视频游戏(名称,游戏封面和发布日期)的信息,如果你想以后玩游戏,或者即使你想添加你已经完成的游戏,只需将游戏添加到你的列表中,这是一个简单的库应用程序。为了将游戏添加到您的列表中,您需要进入游戏所在的页面,用一个简单的按钮将其添加到列表中

现在我恢复了应用程序的功能,让我解释一下该网站是如何工作的

这个网站是用Laravel6构建的,我想实现的所有功能都在运行,除了一个,在你的列表中添加一个游戏。添加一个游戏到你的列表是很好的数据库端,但我的问题是,我不能显示添加到我的“profile”页面的游戏列表

这是我的用户表,名为usilisateurs

下面是名为listes的列表表

我在这两个表中都使用参考用户表中用户id的用户id进行了连接。(当您登录并单击add按钮时,它会获取登录用户的用户id并将其保存在表“listes”中)

一切正常,但我无法成功显示用户在我的视图中添加到列表中的游戏

这是我的密码:

-profil页面的my CompteController.php(显示profil img、名称和注销按钮)

-listcontroller.php(当您单击此按钮并将其添加到“listes”表中时,函数“ajout”将获取游戏名称和登录用户的id)

正如我已经说过的,在数据库中添加数据是可行的

这是我的迁移文件,您可以看到我如何设置数据库:

-迁移利用率表:

    use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUtilisateursTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
    Schema::create('utilisateurs', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->varchar('pseudo');
        $table->varchar('avatar');
        $table->string('email')->unique();
        $table->string('mot_de_passe');
        $table->timestamps();
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::dropIfExists('utilisateurs');
}
}

-迁移列表表:

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateListeTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('listes', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->text('nom');
            $table->integer('utilisateur_id');
            $table->boolean('statut');
            $table->timestamps();
        });
    }


    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('liste');
    }
}
以下是Profil页面的视图:

@extends('layout')
@section('container')
<section id="profile">
    <div class="bloc">
        <h2>Mon Profil</h2>
        <img src="img/soulignement.png" alt="" class="soulignement">
        <div>
            <h3>{{ Auth::user()->pseudo }}</h3>
            <img src="storage/avatars/{{ Auth::user()->avatar }}" class="imageProfil"> <br>
            <div id="centrageBouton">
            <div class="tooltip"> <button class="boutons btnBasique" id="image-profil"><span><i
                            class="fas fa-upload"></i></span></button> <span class="tooltiptext">Changer d'image de profil</span>
            </div> 
        </div><br>
            <div class="formulaire-image">
                <form action="/mon-compte" method="post" enctype="multipart/form-data" id="formulaireUpload">
                    @csrf

                    <input type="file" size="60" class="boutonUpload " name="avatar" id="avatarFile" >

                    <button type="submit" class="btn btn-primary" id="boutonEnvoie">Submit</button>
                </form>
            </div><br>
            <div class="bloc-aligner">

                <button class="boutons btnBasique"><span>Changer mon MDP</span></button>
               <button class="boutons btnBasique"> <a href="/deconnexion"><span> Déconnexion</span></a></button>
            </div>
        </div>
        <div id="mesJeux">
            <h3>Mes Jeux</h3>
            <img src="img/soulignement.png" alt="" class="soulignement">
            <table>
                <tr>
                    <td>Nom</td>
                    <td>Statut</td>
                    <td>Actions</td>

                </tr>

                <tr>
                    <td>The Legend of Zelda: Breath of the Wild</td>
                    <td>finis</td>
                    <td><button class="boutons btnBasique"><span>finis</span></button> <br><button
                            class="boutons btnBasique"><span>à finir</span></button></td>
                </tr>
            </table>
        </div>
    </div>
</section>
<script src="js/Main.js"></script>
<script src="js/AffichageBoutonForm.js"></script>
@endsection
@extends('layout'))
@节(“容器”)
蒙Profil
{{Auth::user()->pseudo}
阿凡达}“class=”imageProfil“>
图像变换器
@csrf 提交
变换器mon MDP 梅斯·杰克斯 笔名 身材 行动 塞尔达传说:野性的气息 菲尼斯 finis
a finir @端部
现在我的问题是,如何在“listes”表中显示添加到数据库中的游戏名称,用户登录时将其添加到列表中并显示在profil页面上

如果我不清楚,我很抱歉,英语不是我的母语,我有点累了,因为我几乎整天都在找这个

如果你们需要补充信息,告诉我,我会给你们的


谢谢。

您需要获取用户游戏的列表并将该列表传递给视图。
Auth::user()->如果您在
usilisateur
模型中设置了关系,则列表应该可以工作。我的模型中没有设置关系,您确定当有人登录并尝试查看他的列表时,列表可以工作吗?
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateListeTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('listes', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->text('nom');
            $table->integer('utilisateur_id');
            $table->boolean('statut');
            $table->timestamps();
        });
    }


    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('liste');
    }
}
@extends('layout')
@section('container')
<section id="profile">
    <div class="bloc">
        <h2>Mon Profil</h2>
        <img src="img/soulignement.png" alt="" class="soulignement">
        <div>
            <h3>{{ Auth::user()->pseudo }}</h3>
            <img src="storage/avatars/{{ Auth::user()->avatar }}" class="imageProfil"> <br>
            <div id="centrageBouton">
            <div class="tooltip"> <button class="boutons btnBasique" id="image-profil"><span><i
                            class="fas fa-upload"></i></span></button> <span class="tooltiptext">Changer d'image de profil</span>
            </div> 
        </div><br>
            <div class="formulaire-image">
                <form action="/mon-compte" method="post" enctype="multipart/form-data" id="formulaireUpload">
                    @csrf

                    <input type="file" size="60" class="boutonUpload " name="avatar" id="avatarFile" >

                    <button type="submit" class="btn btn-primary" id="boutonEnvoie">Submit</button>
                </form>
            </div><br>
            <div class="bloc-aligner">

                <button class="boutons btnBasique"><span>Changer mon MDP</span></button>
               <button class="boutons btnBasique"> <a href="/deconnexion"><span> Déconnexion</span></a></button>
            </div>
        </div>
        <div id="mesJeux">
            <h3>Mes Jeux</h3>
            <img src="img/soulignement.png" alt="" class="soulignement">
            <table>
                <tr>
                    <td>Nom</td>
                    <td>Statut</td>
                    <td>Actions</td>

                </tr>

                <tr>
                    <td>The Legend of Zelda: Breath of the Wild</td>
                    <td>finis</td>
                    <td><button class="boutons btnBasique"><span>finis</span></button> <br><button
                            class="boutons btnBasique"><span>à finir</span></button></td>
                </tr>
            </table>
        </div>
    </div>
</section>
<script src="js/Main.js"></script>
<script src="js/AffichageBoutonForm.js"></script>
@endsection