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

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

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

Vue.jsは、Webアプリケーションのインターフェースを構築するためのオープンソースJavaScriptフレームワークです。

Laravel

LaravelとはTaylor Otwellによって開発された、オープンソースなPHPフレームワークです。Laravelはシンプルで表現的なシンタックスを持ち合わせており、ウェブアプリケーション開発の手助けをしてくれます。

Q&A

解決済

1回答

96閲覧

Reauestがnullになる

ratezou

総合スコア64

Vue.js

Vue.jsは、Webアプリケーションのインターフェースを構築するためのオープンソースJavaScriptフレームワークです。

Laravel

LaravelとはTaylor Otwellによって開発された、オープンソースなPHPフレームワークです。Laravelはシンプルで表現的なシンタックスを持ち合わせており、ウェブアプリケーション開発の手助けをしてくれます。

0グッド

0クリップ

投稿2024/04/27 00:15

編集2024/04/27 00:43

実現したいこと

Udemyで以下の講座を受講しており、
https://www.udemy.com/course/laravel-vue3-crm/learn/lecture/33118760#questions
vue.jsのLinkからLaravelへstoreする箇所で入力値がstoreに渡る箇所がnullになっており、原因がわからず困っています。解決したいです。

発生している問題・分からないこと

入力値がnullで渡り、エラーとなっています。

エラーメッセージ

error

1Illuminate\Database\QueryException 2SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: inertia_tests.title 3INSERT INTO 4 "inertia_tests" ("title", "content", "updated_at", "created_at") 5VALUES 6 (?, ?, 2024 -04 -27 08: 58: 24, 2024 -04 -27 08: 58: 24)

該当のソースコード

```web.php(一部) use Inertia\Inertia; use App\Http\Controllers\InertiaTestController; Route::get('/inertia/index', [InertiaTestController::class, 'index'])->name('inertia.index'); Route::post('/inertia', [InertiaTestController::class, 'store'])->name('inertia.store'); Route::get('/inertia/show/{id}', [InertiaTestController::class, 'show'])->name('inertia.show');

InertiaTest.vue

1<script setup> 2import { Head, Link } from '@inertiajs/vue3'; 3import { ref } from 'vue' 4 5const newTitle = ref('') 6const newContent = ref('') 7 8</script> 9 10<template> 11Inertiaテストです。<br> 12<a href="/">aタグ経由です</a><br> 13<Link href="/">Link経由です</Link><br> 14<Link :href="route('inertia.index')">名前つきルートの確認です</Link><br> 15<Link :href="route('inertia.show', { id: 50 })">ルートパラメータのテストです</Link> 16 17<div class="mb-8"></div> 18<input type="text" name="newTtile" v-model="newTitle" />{{ newTitle }}<br> 19<input type="text" name="newContent" v-model="newContent" />{{ newContent }}<br> 20<Link as="button" method="post" :href="route('inertia.store')" 21:date="{ 22 title: newTitle, 23 content: newContent 24}">DB保存テスト</Link> 25</template>

InertiaTestController.php

1<?php 2 3namespace App\Http\Controllers; 4 5use Illuminate\Http\Request; 6use Inertia\Inertia; 7use App\Models\InertiaTest; 8 9class InertiaTestController extends Controller 10{ 11 public function index() { 12 return inertia::render('Inertia/Index'); 13 } 14 15 public function show($id) { 16 return Inertia::render('Inertia/Show', 17 [ 18 'id' => $id 19 ]); 20 } 21 22 public function store(Request $request) { 23 $InertiaTest = new InertiaTest; 24 $InertiaTest->title = $request->title; 25 $InertiaTest->content = $request->content; 26 $InertiaTest->save(); 27 28 return to_route('inertia.index'); 29 } 30}

InertiaTest.php

1<?php 2 3namespace App\Models; 4 5use Illuminate\Database\Eloquent\Factories\HasFactory; 6use Illuminate\Database\Eloquent\Model; 7 8class InertiaTest extends Model 9{ 10 use HasFactory; 11}
### 試したこと・調べたこと - [x] teratailやGoogle等で検索した - [ ] ソースコードを自分なりに変更した - [ ] 知人に聞いた - [ ] その他 ##### 上記の詳細・結果 chatGPTで調べてみましたが、解決に至りませんでした。 ### 補足 http://127.0.0.1:8000/inertia-testにアクセスして、 titleとcontentのinputに値を入力し、更新をかけるとエラーになります。 storeメソッドまでは行っており、dd($request->title)を見るとたしかにnullになっています。 どうぞご指導のほど、よろしくお願いいたします。 追記1 ちなみに、$requestには何もはいっていませんでした。 (storeでdd($request)しました) ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2024-04-27/def8d13d-5ac4-4cfb-a143-c4fe65f93d58.png) 追記2 nameに綴り間違いがあったので、直したのですが、うまくいかないままです。 newを取ってもうまくいきませんでした。

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

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

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

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

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

guest

回答1

0

自己解決

綴り間違いでした。お騒がせして。すいませんでした。

<Link as="button" method="post" :href="route('inertia.store')" :date="{ title: newTitle, content: newContent }">DB保存テスト</Link>

dateでは無く、dataでした。

投稿2024/04/27 00:58

ratezou

総合スコア64

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.47%

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

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

質問する

関連した質問