laravel入門の本を進めていましたが下記のようなエラーが出ました。
ErrorException (E_NOTICE)
Undefined offset: 0
コードの書き方はあってると思うのですが、原因・対処方法わかる方いましたら回答お願いします。
php
1public function edit(Request $request) 2{ 3 $param = ['id'=>$request->id]; 4 $item = DB::select('select * from people where id = :id', $param); 5 return view('hello.edit', ['form' => $item[0]]); 6} 7 8public function update(Request $request) 9{ 10 $param = [ 11 'id'=>$request->id, 12 'name'=>$request->name, 13 'mail'=>$request->mail, 14 'age'=>$request->age, 15 ]; 16 DB::update('update people set name=:name, mail=:mail, age=:age where id =:id', $param); 17 return redirect('/hello'); 18}
php
1@extends('layouts.helloapp') 2 3@section('title', 'Edit') 4 5@section ('menubar') 6 @parent 7 更新ページ 8@endsection 9 10@section('content') 11 <table> 12 <form action="/hello/edit" method="post"> 13 {{csrf_field()}} 14 <input type="hidden" name="id" value="{{$form->id}}"> 15 <tr><th>name: </th><td><input type="text" name="name" value="{{$form->name}}"></td></tr> 16 <tr><th>mail: </th><td><input type="text" name="mail" value="{{$form->mail}}"></td></tr> 17 <tr><th>age: </th><td><input type="text" name="age" value="{{$form->age}}"></td></tr> 18 <tr><th></th><td><input type="submit" value="send"></td></tr> 19 </form> 20 </table> 21@endsection 22 23@section('footer') 24copyright 2017 tuyano. 25@endsection
php
1Route::get('hello/edit', 'HelloController@edit'); 2Route::post('hello/edit', 'HelloController@update'); 3 4
回答2件
あなたの回答
tips
プレビュー