0

我有一个看起来像这样的模型:

<?php

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

class Post extends Eloquent {
}

然后我尝试添加这样的方法:

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

class Post extends Eloquent {
    public static function create($type, $postid, $url, $author, $content)
    {
        $post = new Post;
        $post->type = $type;
        $post->postid = $postid;
        $post->url = $url;
        $post->author = $author;
        $post->content = $content;
        try
        {
        $post->save();
        echo $post;
        }catch(Exception $e){
            throw new Exception( 'Already saved', 0, $e);
        } 
    }
}

在控制器中,我尝试像这样引用该方法:

public function savepostController($type, $postid, $url, $author, $content)
{
    Post::create($type, $postid, $url, $author, $content);
}

当我运行控制器时,我得到Controller method not found.

4

1 回答 1

0

尝试使用,这是一个例子

class Exports extends Eloquent {

    public static function my_exports($user)
    {
         // DB call here
    }
}

然后在你的路线上你可以做

Route::post('export/(:number)', function($user)
{

    $user_exports = Export::my_exports($user);

    // Do stuff here
});
于 2013-08-19T10:05:55.830 回答