В 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
Получить идентификатор из главной таблицы при вводе в подробную таблицу (Laravel 8) ⇐ Php
Кемеровские программисты php общаются здесь
1728789920
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');
Подробнее здесь: [url]https://stackoverflow.com/questions/70343815/get-id-from-master-table-when-doing-input-for-detail-table-laravel-8[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия