質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
Laravel 5

Laravel 5は、PHPフレームワークLaravelの最新バージョンで、2014年11月に発表予定です。ディレクトリ構造がが現行版より大幅に変更されるほか、メソッドインジェクションやFormRequestの利用が可能になります。

Q&A

解決済

1回答

1063閲覧

Laravel5.7系でレコードidを特定して別アクションに渡したい

amaturePy

総合スコア131

Laravel 5

Laravel 5は、PHPフレームワークLaravelの最新バージョンで、2014年11月に発表予定です。ディレクトリ構造がが現行版より大幅に変更されるほか、メソッドインジェクションやFormRequestの利用が可能になります。

0グッド

0クリップ

投稿2020/01/22 07:54

editアクション(編集)からupdateアクション(更新)に各レコードのユニークidを渡したいのですが、
うまく渡せず困っております。

現状は編集用のedit.blade.phpにidカラムの値を乗せたinputのフォームからupdateアクションにidを
渡してupdateアクションの方でそのレコードのデータか特定しています。ですが、編集画面にはユニークキーは乗せない(入力しなくてもいい)ように処理したいです。

もし参考になる資料などありましたらご教授頂きたいです。

<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use \App\Model\ChatConversation; class ChatConversationController extends Controller { public function __construct() { $this->middleware('auth'); } public function index() { $chat_conversations = ChatConversation::paginate(10); return view('chat_conversations/index',['chat_conversations' => $chat_conversations]); } public function show($id) { $chat_conversations = ChatConversation::find($id); return view('chat_conversations/show')->with('chat_conversations',$chat_conversations); } public function create() { return view('chat_conversations/create'); } public function store(Request $request) { $validatedData = $request->validate([ 'node_id' => 'required', 'line_id' => 'required', 'message'=>'required', 'version_type' => 'required', 'ip_addr' => 'required', 'platform'=>'required', 'translate'=>'required' ]); $chat_conversations = new ChatConversation(); $chat_conversations->node_id = $request->node_id; $chat_conversations->line_id = $request->line_id; $chat_conversations->message = $request->message; $chat_conversations->version_type = $request->version_type; $chat_conversations->ip_addr = $request->ip_addr; $chat_conversations->platform = $request->platform; $chat_conversations->translate = $request->translate; $chat_conversations->save(); return redirect('/chat_conversations'); } public function edit(Request $request){ $chat_conversations = ChatConversation::find($request->id); return view('chat_conversations/edit', ['chat_conversations'=>$chat_conversations]); } public function update(Request $request) { $chat_conversations = new ChatConversation(); $chat_conversations = ChatConversation::find($request->id); $chat_conversations->node_id = $request->node_id; $chat_conversations->line_id = $request->line_id; $chat_conversations->message = $request->message; $chat_conversations->version_type = $request->version_type; $chat_conversations->ip_addr = $request->ip_addr; $chat_conversations->platform = $request->platform; $chat_conversations->translate = $request->translate; $chat_conversations->save(); return redirect('/chat_conversations'); } } ?> コード
@extends('layouts.app') @section('content') <div class="container"> <div class="row justify-content-md-center"> <div class="col-6"> {{Form::open(['action' => 'ChatConversationController@update','method'=>'Post'])}} <div class="form-group"> <label for="exampleFormControlInput1">node_id</label> <input type="text" class="form-control" name="node_id" value='{{ $chat_conversations->node_id }}'> </div> <div class="form-group"> <label for="exampleFormControlInput1">line_id</label> <input type="text" class="form-control" name="line_id" value='{{ $chat_conversations->line_id }}'> </div> <div class="form-group"> <label for="exampleFormControlInput1">message</label> <input type="text" class="form-control" name="message" value='{{ $chat_conversations->message }}'> </div> <div class="form-group"> <label for="exampleFormControlInput1">version_type</label> <input type="text" class="form-control" name="version_type" value='{{ $chat_conversations->version_type}}'> <div class="form-group"> <label for="exampleFormControlInput1">ip_addr</label> <input type="text" class="form-control" name="ip_addr" value='{{ $chat_conversations->ip_addr }}'> </div> <div class="form-group"> <label for="exampleFormControlInput1">platform</label> <input type="text" class="form-control" name="platform" value='{{ $chat_conversations->platform}}'> </div> <div class="form-group"> <label for="exampleFormControlInput1">translate</label> <input type="text" class="form-control" name="translate" value='{{ $chat_conversations->translate }}'>  </div> <input type="submit" class="btn btn-primary" name="post" value="Send"> {{Form::close()}} </div> </div> </div> @endsection コード
Route::get('product_orders/{id}/edit', 'ProductOrderController@edit')->name('edit'); Route::post('product_orders/update', 'ProductOrderController@update')->name('update'); コード

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

私が回答した、こちらのコードを参考にしてもらうと理解できると思います。
https://teratail.com/questions/234029#reply-340822

投稿2020/01/22 08:01

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

amaturePy

2020/01/22 09:36

ありがとうございます。 参考にさせて頂きます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問