Error sending information to the bank. Editing form

Asked

Viewed 40 times

0

I have an edit form for a post feed. When I click to save the edit the following error appears:

SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column "title" 
violates not-null constraint
DETAIL: Failing row contains (1, 1, null, null, null, 2018-04-24 10:04:55). 
(SQL: update "feeds" set "title" = , "description" = , "updated_at" = 2018- 
04- 24 10:04:55 where "id" = 1)

It’s like I’m sending you blank information, but there’s nothing blank.

feed-update.blade.php

@extends('layouts.app')

@section('content')
<div class="container">
    <form action="<?php echo action('HomeController@save', $feed->id); ?>" method="POST">
       <input type="hidden" name="_token" value="<?php echo csrf_token(); ?> ">
       <h1>Editar Post</h1>
       <b>Publicado por: {{$feed->user->name}} </b><br>


       <b>Título:</b><input class="form-control" type="text" value="{{$feed->title}}">
       <br>
       <b>Descrição:</b><input class="form-control" type="text" value="{{$feed->description}}">
       <br>

       <button type="submit" class="btn btn-success">Salvar</button>    
   </form>
</div>
@endsection

Homecontroller@save

    public function save($idFeed)
    {
       $title = Request()->input('description');
       $description = Request()->input('title');

       $feed = feed::find($idFeed);
       $feed->description = $description;
       $feed->title = $title;
       $feed->save();

       return redirect()->action('HomeController@index');
    }

1 answer

2


Form Fields do not have the attribute name, so they’re not being received in the controller. Follows correction:

@extends('layouts.app')

@section('content')
<div class="container">
    <form action="<?php echo action('HomeController@save', $feed->id); ?>" method="POST">
       <input type="hidden" name="_token" value="<?php echo csrf_token(); ?> ">
       <h1>Editar Post</h1>
       <b>Publicado por: {{$feed->user->name}} </b><br>


       <b>Título:</b><input class="form-control" type="text" value="{{$feed->title}}" name="title">
       <br>
       <b>Descrição:</b><input class="form-control" type="text" value="{{$feed->description}}" name="description">
       <br>

       <button type="submit" class="btn btn-success">Salvar</button>    
   </form>
</div>
@endsection
  • 1

    Another point is the $title inversion receiving the Description field.

  • It worked, thank you.

  • Yeah, I just tidied up.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.