dimanche 11 août 2019

Fix how to get the course record by using programme id

Im trying to do get the course record by using the programme id in a many to many relationship.What did i write in the controller?

This is my programme table,course table and progcourse table:

public function up()
{
    Schema::create('programmes', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('code')->unique;
        $table->string('name');
        $table->string('desc');
        $table->string('mer');
        $table->integer('duration');
        $table->string('campus');
        $table->timestamps();
    });
}


public function up()
{
    Schema::create('courses', function (Blueprint $table) {
    $table->bigIncrements('id');
        $table->string('code')->unique;
        $table->string('name');
        $table->string('desc');
        $table->string('fee');

        $table->timestamps();
    });
}

public function up()
{
    Schema::create('prog_courses', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->integer('Programme_id')->unsigned();
        $table->integer('Course_id')->unsigned();
        $table->foreign('Programme_id')->references('id')->on('Programmes');
        $table->foreign('Course_id')->references('id')->on('Courses');
        $table->timestamps();
    });
}

And this is my show function

public function show($id)
{   
    $courses = Course::where('id',$id)->get();

    $programmes = Programme::where('id', $id)->firstOrFail();

    return view('progdetails')->with([
            'programmes' => $programmes,
            'courses' => $courses
            ]);
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire