So basically the error states that i don't have a column called updated_at but i know i dont have it and i dont want to have it. My database table only has the following columns : requester, user_requested, id, status.

this is my model

class Friendships extends Model
{
    protected $fillable = ['requester', 'user_requested', 'status'];
}

this is my profilecontroller

 public function sendRequest($id){
        return Auth::user()->addFriend($id);

  }

And this is my friendable.php


namespace App\Traits;
use App\Friendships;

trait Friendable{
    public function test(){
        return 'hi' ;
    }

    public function addFriend($id){
        $Friendship = Friendships::create([
                'requester' => $this->id,
                'user_requested' => $id
        ]);


        if($Friendship){
            return $Friendship;
        }
        return  'failed';
    }


}

it says that method addFriend isnt found and the create doesnt work apparently because the id isnt found.

2 Answers

2
Rahul Meshram On Best Solutions

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:

class Friendships extends Model
{
    public $timestamps = false;
    protected $fillable = ['requester', 'user_requested', 'status'];
}  

EDIT

fire commands,

php artisan make:migration modify_friendships_table;

Then go to migration file which is generated in database/migrations

Write code in that class,

Schema::table('friendships', function (Blueprint $table) {
    $table->boolean("status")->default(0)->change();
});

save above file, then fire below command

php artisan migrate

And now check, if its working.

0
George Hanson On

Laravel will automatically try to set the value for created_at and updated_at fields. It is highly recommended to have these, however if you don't want to you can disable them on your Model.

To do this simply add public $timestamps = false; to the model. For example:

class Friendships extends Model
{
    public $timestamps = false;
    protected $fillable = ['requester', 'user_requested', 'status'];
}