Esou recebendo esse erro e não consigo identificar qual a relação do campo com o insert, to perdido alguém pra dar um help?
SQLSTATE[HY000]: General error: 1364 Field 'number' doesn't have a default value
INSERT INTO
seasons
(updated_at
, created_at
)
VALUES
(2024 -05 -08 20: 38: 18, 2024 -05 -08 20: 38: 18)
Model:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Seasons extends Model
{
use HasFactory;
protected $fillable = ['number'];
public function series()
{
return $this->belongsTo(Series::class);
}
public function episodes(): HasMany
{
return $this->hasMany(Episode::class);
}
Migration
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('seasons', function (Blueprint $table) {
$table->id();
$table->unsignedTinyInteger('number');
$table->foreignId('series_id')->constrained()->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('seasons');
}
};
O erro ocorre no update da EpisodesController
class EpisodesController
{
public function index(Seasons $seasons)
{
return view('episodes.index', ['episodes' => $seasons->episodes]);
}
public function update(Request $request, Seasons $seasons)
{
$watchedEpisodes = $request->episode;
$seasons->episodes()->each(function (Episode $episode) use ($watchedEpisodes)
{
$episode->watched = in_array($episode->id, $watchedEpisodes);
});
$seasons->push();
return to_route('episodes.index', $seasons->id);
}
}