1

I'm trying to update a value in a database in laravel4. It's a bit of a cornercase, I have just a single entry in the database with a session-id in it. it's used to authenticate against facebook.

This is the model:

<?php

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;

    class Accesstoken extends Eloquent {

    public static function createpost($token)
    {
        $accesstoken = new Accesstoken;
        $accesstoken->accesstoken = $token;
        $accesstoken->save();
    }

    public static function update($token)
    {
        $accesstoken = Accesstoken::find(1);
        $accesstoken->accesstoken = $token;
        $accesstoken->save();
    }
}

It's the second function that is wrong. If I try to add it before doing a migrate, I can't migrate and if I try to call it like this

Accesstoken::update($access_token);

I get the following error, why?

Cannot make non static method Illuminate\Database\Eloquent\Model::update() static in class Accesstoken

1
  • 1
    Eloquent\Model already implements a method public function update(array $attributes = array()) that isn't static. Commented Aug 29, 2013 at 16:15

1 Answer 1

2

There's an update() method in Eloquent already. Try something like

<?php

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;

    class Accesstoken extends Eloquent {

    public static function createpost($token)
    {
        $accesstoken = new Accesstoken;
        $accesstoken->accesstoken = $token;
        $accesstoken->save();
    }

    public static function updateToken($token)
    {
        $accesstoken = Accesstoken::find(1);
        $accesstoken->accesstoken = $token;
        $accesstoken->save();
    }
}

And

Accesstoken::updateToken($access_token);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.