samedi 3 septembre 2016

How to do query select * from a where id = id in Laravel?

I have two tables (edition and journal) both related with one to many relationship (one edition has many journals). What I wanted to know is that how to show all journals data from a single edition ? for example like this query "select * from journals where id_edition ='$_GET[id]' order by id DESC" which is working on normal sql but I don't know how to do it in Laravel. Here is the table structure :

Edition table :

    Schema::create('edition', function (Blueprint $table) {
                $table->increments('id');
                $table->string('title')->unique();
                $table->text('cover')->nullable();
                $table->timestamps();
            });

Schema::table('journal', function(Blueprint $table) {
            $table->foreign('id_edition')->references('id')->on('edition')->onDelete('cascade')->onUpdate('cascade');
        });

Journals table :

public function up()
    {
        Schema::create('journal', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title', 200);
            $table->string('author');
            $table->text('abstract');
            $table->text('file');
            $table->integer('id_edition')->unsigned();
            $table->timestamps();
        });
    }

I came up with this $jurnal_list = DB::table('journal')->where('id_edition', '=', edition/' . $edition->id')->get(); but it's not working



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire