[英]How to update value in table in database, laravel?
I'm trying to update a value in a database in laravel4. 我正在尝试在laravel4中更新数据库中的值。 It's a bit of a cornercase, I have just a single entry in the database with a session-id in it.
这有点麻烦,我在数据库中只有一个条目,其中有一个会话ID。 it's used to authenticate against facebook.
用于对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 无法在类Accesstoken中将非静态方法Illuminate \\ Database \\ Eloquent \\ Model :: update()设为静态
There's an update() method in Eloquent already. Eloquent中已经有一个update()方法。 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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.