Reputation: 15026
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
Upvotes: 1
Views: 4261
Reputation: 87789
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);
Upvotes: 2