laravel에서 작성중인 블로그 게시물을 업데이트하는 데 도움이 필요합니다. 나는 이것을 처리하기 위해 편안한 컨트롤러에서 update 메소드를 사용하고있다. 폼에 컨트롤러 (업데이트 메서드) 내의 올바른 함수에 제출되고 있지만 데이터베이스의 테이블에 변경 내용이 반영되지 않는 것 같습니다. 단지 있는지 확인하기 위해 나는 $ 제목과 return 문에 $ 콘텐츠 변수를 추가Laravel에서 양식 업데이트
public function update(PostRequest $request, $id)
{
$title = $request->title;
$content = $request->content;
DB::table('posts')->where('id', $id)->update(['title' => $title, 'content' => $content]);
return 'Post was updated.<br>' . $title . '<br>' . $content;
}
여기
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Register</div>
<div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="{{ url('/posts/$post_id') }}">
{{ csrf_field() }}
<input type="hidden" name="_method" value="PUT">
<div class="form-group{{ $errors->has('title') ? ' has-error' : '' }}">
<label for="title" class="col-md-4 control-label">Title</label>
<div class="col-md-6">
<input id="title" type="text" class="form-control" name="title" value="{{ !empty(old('title')) ? old('title') : $post->title }}" required autofocus>
@if ($errors->has('title'))
<span class="help-block">
<strong>{{ $errors->first('title') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('content') ? ' has-error' : '' }}">
<label for="content" class="col-md-4 control-label">Content</label>
<div class="col-md-6">
<textarea id="content" type="text" class="form-control" name="content" required rows="15" cols="20">{{ !empty(old('content')) ? old('content') : $post->content }}</textarea>
@if ($errors->has('content'))
<span class="help-block">
<strong>{{ $errors->first('content') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Post
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
@endsection
컨트롤러 기능입니다 : 여기
내가 양식이 무엇인가 그들은 정상을 통과하고 제대로 포착되었습니다. 양식을 제출할 때 여기에 적힌대로 반환 명세서를받습니다. 적어도 양식이이 함수에 올바르게 제출한다는 것을 알려주지 만, 제가 말한 것처럼 데이터베이스는 변경 사항을 반영하지 않습니다. 아무도 내가 여기서 뭘 잘못하고 있는지 알아? 숨겨진 inout 필드를 사용하여 PUT 메소드의 스텁에 대해 올바르게 작동하지 않는 업데이트 명령인지 확실하지 않습니다.미리 감사드립니다.
는 질문과 관련,하지만 내가보기 엔 ** ** 웅변 모델을 사용하는 것이 좋습니다 것 아니 .. 당신을 위해 도움이된다 생각합니다. 그런 다음 업데이트 쿼리는'$ post-> update(); '와 같이 간단합니다. – linuxartisan
SQL 쿼리를 디버깅하지 않고 업데이트 쿼리를 표시하는 이유는 무엇입니까? – Kamal