Получить идентификатор из главной таблицы при вводе в подробную таблицу (Laravel 8)Php

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Получить идентификатор из главной таблицы при вводе в подробную таблицу (Laravel 8)

Сообщение Anonymous »

В laravel я хочу получить идентификатор от мастера таблиц.
public function up()
{
Schema::create('landings', function (Blueprint $table) {
$table->id();
$table->string('title')->nullable();
$table->text('content')->nullable();
$table->text('photo')->nullable();
$table->timestamps();
});
}

public function up()
{
Schema::create('landingmetas', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('landing_id');
$table->foreign('landing_id')->references('id')->on('landings')->onDelete('cascade')->onUpdate('cascade');
$table->string('meta_key')->unique();
$table->string('meta_value')->nullable();
$table->timestamps();
});
}

мой контроллер для сохранения данных в таблице лендингов:
public function store(Request $request)
{
$landings = new Landing();

$landings->title = $request->title;

$landings->save();
Session::flash('landing-add','Section telah dibuat.');
return redirect()->route('landing.createlm', $landings->id);
}

в строке return redirect()->route('landing.createlm', $landings->id); я перенаправляюсь на Landing.createlm.blade.php (форма для входных данных во вторую таблицу). это сработало, но мне сложно вводить данные в Landingmetas, потому что я понятия не имею, как получить этот идентификатор URL.
мой контроллер для хранения данных в Landingmetas (подробная таблица):public function storelm(Request $request)
{
$lm = new Landingmeta();

$meta_key = strtolower($request->meta_key);
$meta_key = str_replace(" ", "", $meta_key);
$lm->meta_key = substr($meta_key, 0, 3)."-".substr($meta_key, 3);
$lm->landing_id = ???? (here id from master table)

$lm->save();
Session::flash('add-field','Field telah ditambahkan.');
return back();
}

мой маршрут:
/*Landing page*/
Route::get('/landings', [App\Http\Controllers\LandingController::class, 'index'])->name('landing.index');
Route::post('/landings', [App\Http\Controllers\LandingController::class, 'store'])->name('landing.store');
Route::get('/landings/{landing}/create', [App\Http\Controllers\LandingController::class, 'edit'])->name('landing.edit');
Route::delete('/landings/{landing}/destroy', [App\Http\Controllers\LandingController::class, 'destroy'])->name('landing.destroy');
/*Create Landingmetas*/
Route::get('landings/{landing}/createfield', [App\Http\Controllers\LandingController::class, 'createlm'])->name('landing.createlm');
Route::post('/landinglm', [App\Http\Controllers\LandingController::class, 'storelm'])->name('landing.storelm');


Подробнее здесь: https://stackoverflow.com/questions/703 ... -laravel-8
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»