Laravel error after inserting the save() method



  • Good afternoon I am tried at all costs to make an insert in the bank, using the Laravel and Controller, however, it does not work at all, I have tried everything that is shape, making migrate, changing screen name, anyway, in all manners and nothing. In my script, I have this code:

    Route::when('*', 'csrf', array('post'));
    Route::get('/', 'HomeController@getIndex');
    Route::post('save', 'HomeController@postAddUser');
    Route::post('login', 'HomeController@postLogin');
    Route::group(array('before' => 'auth'), function(){
       Route::controller('profile', 'ProfilesController');
    });
    

    In my Controller, I have the following action:

    public function postInserir(){
        $posts = new Post();
        $posts->nome = Auth::user()->nome;
        $posts->post = Input::get('text_post');
        $posts->save();
    
    return Redirect::to('/');
    

    }

    Model:

     class Post extends Eloquent{

    }

    In my bank, I have a table called posts with an id auto increment not null, a field called varchar name 255 not null and a field called post longtext

    And this is my View:

    <?php echo Form::open(array('action' => 'ProfilesController@postInserir', 'role' => 'form', 'id' => 'post-form')); ?>
    <div class="panel-body">
    <textarea id="text_post" name="text_post" class="form-control" rows="2"></textarea>
    </div>
    <div class="panel-footer" style="background-color: black;">

            &lt;button type="submit" id="publicar" class="btn btn-primary btn-xs pull-right"&gt;Publicar&lt;/button&gt;
            &lt;?php echo Form::close(); ?&gt;
    

    If I submit the form, it goes to the action, it displays what was passed and everything else, the problem and when I do I call the $posts->save() method, which gives me the Message "Whoops, looks."

    Does anyone know where the problem might be?



  • This is happening because in your table has not created the created_at and updated_ad columns, to add them in your table, in your schema add the line

    $this->timestamps();
    

    so it will create these columns.

    But if you really aren't going to use for it's a pivot table etc, you can tell the model that by making some change and inserting, don't go popular these columns to this go in the model and add this line

    public $timestamps = false;
    

    Okay, that's it!




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2