Your title is about 'date format' and your error is 'missing level column'!? The error is due to the lack of level column definition in Schema::create('skill_user...
Nov 29, 2020
23
Level 10
SQLSTATE[22007] Invalid datetime format 1366 Incorrect integer value:a field for column
After login a user, The user enters this skills form, selects the skills.
*A user can enter multiple skills, and save in database. The field of name
-
skill_name
-
level And in table
-
skill_name
-
level
-
user_id I don't know if the
skillsandskill_usertable should be, or not, I don't know. What would you do if you were me? Can you show me the cleanest coding?*public function up() { Schema::create('skills', function (Blueprint $table) { $table->bigIncrements('id'); $table->bigInteger('user_id')->unsigned(); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->string('skill_name'); $table->smallInteger('level'); $table->timestamps(); }); Schema::create('skill_user', function (Blueprint $table) { $table->bigInteger('skill_id')->unsigned()->nullable(); $table->foreign('skill_id')->references('id')->on('skills')->onDelete('cascade'); $table->bigInteger('user_id')->unsigned()->nullable(); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->unique(['skill_id' , 'user_id']); }); }
blade
showDynamicExperimental();
function showDynamicExperimental()
{
let html = '' +
'@foreach(auth()->user()->skills as $skill)\n'+
'<div class="col-md-6 position-relative">\n' +
'<i class="fas fa-times text-danger position-absolute"></i>' +
'<div class="row">\n' +
'<div class="col-md-8">\n' +
'<div class="form-group">\n' +
'<label for="skill_name">skill_name</label>\n' +
'<input type="text" id="skill_name" name="skill_name[]" class="form-control" value="{{ $skill->skill_name }}">\n' +
'</div>\n' +
'</div>\n' +
'<div class="col-md-4">\n' +
'<div class="form-group">\n' +
'<label for="level">level</label>\n' +
'<select class="form-control" id="level" name="level[]">\n' +
'<option value="1" {{ $skill->level == 1 ? 'selected' : '' }}>★☆☆☆☆</option>\n'+
'<option value="2" {{ $skill->level == 2 ? 'selected' : '' }}>★★☆☆☆</option>\n'+
'<option value="3" {{ $skill->level == 3 ? 'selected' : '' }}>★★★☆☆</option>\n'+
'<option value="4" {{ $skill->level == 4 ? 'selected' : '' }}>★★★★☆</option>\n'+
'<option value="5" {{ $skill->level == 5 ? 'selected' : '' }}>★★★★★</option>\n'+
'</select>\n'+
'</div>\n' +
'</div>\n' +
'</div>\n' +
'</div>\n ' +
'@endforeach';
$('#showExperimental').append(html);
}
Controller
$user->skills()->detach();
if ($request->skill_name) {
foreach ($request->skill_name as $key => $value) {
$user->skills()->attach($value, [
'user_id' => auth()->id(),
'level' => $request->level[$key],
]);
}
}
User.php
public function skills()
{
return $this->belongsToMany(Skill::class)->withPivot('skill_name');
}
I get this error.
Please or to participate in this conversation.



