Error in Laravel after inserting save()

Asked

Viewed 890 times

1

Good afternoon I am trying at all costs to make an Internet in the bank, using the Laravel and Controller, however, it does not work at all, I have tried everything that is way, migrating, changing screen name, anyway, all the ways and nothing. On my Rote, 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 database, I have a table called posts with an auto id incremento not null, a field called varchar 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;">

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

If I submit the form, it goes up 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?

1 answer

3

This is happening because in your table you have not created the columns created_at and updated_ad, to add them in your table, in your schema add the row

$this->timestamps();

this way he will create these columns.

But if you’re not really going to use it because it’s a pivot table etc, you can tell the model that by making some changes and inserting, you won’t be popular with those columns for this goes in the model and add this line

public $timestamps = false;

All right, that’s it!

  • If your answer is sufficient to solve the author’s problem, if possible, elaborate your answer better.

  • I edited and explained in more detail

Browser other questions tagged

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