ВК
table images
Schema::create('images', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('img1');
$table->string('img2');
$table->timestamps();
});
=======================
table posts
Schema::create('posts', function (Blueprint $table) {
$table->bigIncrements('id');
$table->foreignId('images_id')
->constrained('images')
->onUpdate('cascade')
->onDelete('cascade');
$table->timestamps();
});
=============================================
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->foreignId('images_id')
->constrained('images')
->onUpdate('cascade')
->onDelete('cascade');
$table->string('name');
$table->timestamps();
});
}
===========
public function up()
{
Schema::create('images', function (Blueprint $table) {
$table->id();
$table->string('img1');
$table->string('img2');
$table->timestamps();
});
}
===========
$data = $req->input(); // data save
try {
// create obj
$post = new Post();
$img = new Image();
// posts
$post->name = $data['name'];
//images
$img->img1 = $data['img1'];
$img->img2 = $data['img2'];
// save
$post->save();
$img->save();
использую save или так нельзя insertтить?