0

I have these two functions.When I try to insert data I get this error

Column not found: 1054 Unknown column 'updated_at&#039 

So it keeps searching for 'created at' and 'updated at' tables, but I've got rid of it before and replaced it with 'joined' and 'leaved'. How to fix it?

In BroadcastServiceProvider

Broadcast::channel('chat', function ($user) {
        $ip = Request::ip();
        $time = now();        
        if (auth()->check() && !session()->has('name'))  { 
            UserInfo::storeUser();
            session()->put('name',$user->name);
            return [
                'id' => $user->id,
                'ip' => $ip,
                'name' => $user->name,
                'joined' => $time,
            ];
        }
    });

Schema

   Schema::create('user_info', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('ip');
        $table->string('joined');
        $table->string('leaved');
    });

In LoginController

 public function logout() {
    auth()->logout();
    session()->forget('name');
    session()->put('leaved',now());
       return redirect('/');
}
Brad_Fresh
  • 119
  • 2
  • 11

5 Answers5

3

What you need, is to add to the model UserInfo the following:

public $timestamps = false
Simon
  • 179
  • 1
  • 11
2
public $timestamps = false;

Add this code in Model.

Yasin Patel
  • 5,624
  • 8
  • 31
  • 53
1

By default, Eloquent expects created_at and updated_at columns to exist on your tables.

If you do not wish to have these columns automatically managed by Eloquent, set the $timestamps property on your model to false:

/**
 * Indicates if the model should be timestamped.
 *
 * @var bool
 */
public $timestamps = false;

If you need to customize the names of the columns used to store the timestamps, you may set the CREATED_AT and UPDATED_AT constants in your model:

const CREATED_AT = 'creation_date';
const UPDATED_AT = 'last_update';

See also:

Eloquent Model Conventions

Rayann Nayran
  • 1,135
  • 7
  • 15
0

Here is model structure in laravel where you can add timestamps to be false.

    <?php

    namespace App;

    use Illuminate\Database\Eloquent\Model;

    class modelName extends Model    
    {      
        protected $table = 'tableName';

        public $timestamps = false; //add this line
    }
MaartenDev
  • 5,631
  • 5
  • 21
  • 33
Rahul Gupta
  • 991
  • 4
  • 12
  • Code-only answers are generally frowned upon on this site. Could you please edit your answer to include some comments or explanation of your code? Explanations should answer questions like: What does it do? How does it do it? Where does it go? How does it solve OP's problem? See: [How to anwser](https://stackoverflow.com/help/how-to-answer). Thanks! – Eduardo Baitello Sep 27 '19 at 13:02
0

Laravel offers a better way to MUTE some particular fields in your table schema. For your case the correct way to remove the created at and the updated at columns in your table would be to do so in the Model itself rather than commenting out the timestamps in the migration file.

In the model for you can MUTE the timestamps as shown below :

public $timestamps = false;

This prevents the created_at and the updated_at columns not to be created while running migrations.

In the event you want to reuse the updated_at and the created_at column by renaming them, then you can do so still in the model as :

const CREATED_AT = 'joined_at';
const UPDATED_AT = 'logged_out_at';

Modifying defaults traits in laravel model :

https://laravel.com/docs/8.x/eloquent

stanley mbote
  • 956
  • 1
  • 7
  • 17