I have a simple crud app with just one input , post title
Here is post table
post table
id title
1 sdss
2 pani
Here is my update function in post controller
public function update(Request $request, $id)
{
$post = Post::find($id);
$post->$request = $request->get('title');
$post->save();
return redirect("/posts")->with("success", "Data updated");
}
Here is my model
class Post extends Model
{
protected $fillable =["title"];
}
Here is html
@section('content')
<div class="content">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<form method="post" action="" class="form-horizontal">
@csrf
@method('PATCH')
<div class="card ">
<div class="card-header card-header-primary">
<h4 class="card-title"></h4>
<p class="card-category"></p>
</div>
<div class="card-body ">
<div class="row">
<div class="col-md-12 text-right">
<a href="" class="btn btn-sm btn-primary"></a>
</div>
</div>
<div class="row">
<label class="col-sm-2 col-form-label"></label>
<div class="col-sm-7">
<div class="form-group">
<input type="text" class="form-control" name="title" value=""/>
</div>
</div>
</div>
</div>
<div class="card-footer ml-auto mr-auto">
<button type="submit" class="btn btn-primary"></button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
@endsection
Now when I click save button to update data I get the following error
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the
manual that corresponds to your MariaDB server version for the right syntax to use near '.`8,
application/signed-exchange;v=b3 Accept-Encoding: gzip, deflate,
' at line 1 (SQL: update `posts` set `PATCH /posts/2 HTTP/1`.`1 Accept:
am new to laravel
What do I need to do to solve this problem?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire