#SOLVED Data wont store in the database.

13 messages · Page 1 of 1 (latest)

deft gate
#

anyone encountered this?
so I used modal and put this to create
array:4 [▼ // app\Http\Controllers\CollegeController.php:53
"_token" => "OKgTuMpWy94YOl5YsGRccnVQNZler15tGgoeSvNF"
"subjectCode" => "1"
"subjectName" => "1"
"units" => "1"
]

that is the result of the dd for debugging but when I look at my database nothing is stored there. Any possible errors?

viral bloom
#

We can't guess what the problem might be. Show the actual code trying to save to the database, and any error messages you get.

Is nothing saved at all, or are some fields filtered out?

deft gate
#

Nothing save at all, Since I'm using laravel I will post the Model, Route, Controller and migration.

deft gate
#

Controller

public function storeCollegeManagementSubject(Request $request)
    {
        $request->validate([
            'subject_code' => 'required',
            'subject_name' => 'required',
            'units' => 'required',
        ]);
    
        $subjects = CollegeManagementSubject::create([
            'subject_code' => $request->input('subject_code'),
            'subject_name' => $request->input('subject_name'),
            'unit' => $request->input('units'),
        ]);
    
        return redirect()->route('college.college-management_subject')->with('success', 'Subject created successfully!');
    }

Route

Route::post('/management-subject', [CollegeController::class, 'storeCollegeManagementSubject'])->name('college-management_subject');

Model


use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class CollegeManagementSubject extends Model
{
    use HasFactory;
    protected $fillable = [
        'subject_code',
        'subject_name',
        'unit',
    ];
}```

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('college_management_subjects', function (Blueprint $table) {
            $table->id();
            $table->string('subject_code');
            $table->string('subject_name');
            $table->integer('unit');
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('college_management_subjects');
    }
};
#

partial view

<form action="{{ route('college.college-management_subject') }}" method="POST" onsubmit="alert('Form submitted!')">
@csrf

...

<input type="text" id="subjectCode" name="subjectCode"
<input type="text" id="subjectName" name="subjectName"
<input type="number" id="units" name="units"

                                                    <div class="flex justify-center">
                                                        <button type="submit" class="bg-yellow-600 hover:bg-yellow-700 text-white font-bold py-2 px-4 rounded">
                                                            Save Changes
                                                        </button>
                                                    </div>
                                                </form>

#

Is it on the validate? thats why it can't store?

viral bloom
#

subject_code vs subjectCode

#

But, you don't need to guess, look at response data and/or error logs.

deft gate
#

oks thanks!

deft gate
#

it works!

deft gate
#

SOLVED Data wont store in the database.

wanton bloom