How to update approved from 0 to 1 in laravel

Posted 1 year ago by irankhosravi

Hi following are my relations.

SubmitApplication.php

public function requisition()
{
    return $this->hasMany(Requisition::class);
}

Requisition.php

public function submitApplication()
{
    return $this->belongsTo(SubmitApplication::class);
}

My blade

<form class="btn-group" action="{{ route('requisitions.update', ['id' => $requisition->id]) }}" method="post">
    {{ method_field('PATCH') }}
    {{ csrf_field() }}
    <button type="submit" class="btn btn-success btn-xs">تایید</button>
</form>

RequisitionController.php

public function update(Request $request, SubmitApplication $submitApplication)
{
    $submitApplication->approved = 1;
    $submitApplication->save();
    return redirect()->back();
}

For requisitions table:

public function up()
{
    Schema::create('requisitions', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('school_id')->unsigned();
        $table->string('type');
        $table->string('status');
        $table->string('date');
        $table->timestamps();
        
        $table->foreign('school_id')->references('id')->on('schools');
    });
}

For submit_applications table:

public function up()
{
    Schema::create('submit_applications', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('requisition_id')->nullable()->unsigned();
        $table->integer('school_id')->nullable()->unsigned();
        $table->integer('approved')->nullable(true);
        $table->string('application')->nullable(true);
        $table->timestamps();
        $table->foreign('requisition_id')->references('id')->on('requisitions');
        $table->foreign('school_id')->references('id')->on('schools');
    });
}

When I click approved button. it added. id do not want add

Databasse

Maybe am I doing wrong?

Please sign in or create an account to participate in this conversation.