Php 运行分页时不允许对闭包进行序列化

Php 运行分页时不允许对闭包进行序列化,php,laravel,laravel-4,closures,laravel-pagination,Php,Laravel,Laravel 4,Closures,Laravel Pagination,当我使用上述Laravel代码时,页面显示: 不允许对“Closure”进行序列化 上面的代码不允许这样写,因为larvel doc似乎没有这些信息 加: 当我把它改成 $posts = Post::where('content', 'like', '%'.$keyword.'%')->paginate(5); 它显示另一个错误: 调用未定义的方法Illumb\Database\Eloquent\Collection::links() 我搜索了网页,它告诉我添加paginate(),这可

当我使用上述Laravel代码时,页面显示:

不允许对“Closure”进行序列化

上面的代码不允许这样写,因为larvel doc似乎没有这些信息

加: 当我把它改成

$posts = Post::where('content', 'like', '%'.$keyword.'%')->paginate(5);
它显示另一个错误:

调用未定义的方法Illumb\Database\Eloquent\Collection::links()

我搜索了网页,它告诉我添加paginate(),这可以解决分页链接的问题。但仍然不能

所有代码

$posts = Post::where('content', 'like', '%'.$keyword.'%')->get();
我的路线:

   public function search(){
        $keyword = Input::get('keyword');
        if(empty($keyword)){
            return Redirect::route('postIndex');
            //->with('message',array('type' => 'alert', 'content' => '不能为空'))
        }
        $posts = Post::where('content', 'like', '%'.$keyword.'%')->paginate(5);
        return Redirect::route('searchResults')->with('posts', $posts);
   }

   public function searchResults(){
     return View::make('frontend.search.search',['posts' => Session::get('posts')]);
   }
加: 后模型

  Route::post('post/search', array(
    'before' => 'csrf',
    'uses' => 'SearchController@search',
    'as' => 'search'  
  ));
  Route::get('post/searchResults', array(

    'uses' => 'SearchController@searchResults',
    'as' => 'searchResults'  
  ));
//$keyword表单的内容:

use Illuminate\Database\Eloquent\SoftDeletingTrait;
class Post extends Eloquent{
  use SoftDeletingTrait;
   protected $dates = ['deleted_at'];

  public static $rules = array(

            'title' => 'required|between:2,80',//unique, 参考users表的设置
            'summary' => 'required|between:20,300',
            'content' => 'required|min:50',

              'tags' => 'required|min:2',
    );  

  protected $fillable = ['title', 'content','summary', 'category'];

  public function tags()
  {
    return $this->belongsToMany('Tag');
  }

    public function category()
  {
    return $this->belongsTo('Category');
  }


  public function user()
  {
    return $this->belongsTo('User');
  }

   public function reviews(){
        return $this->hasMany('Review');//Review is the model of Review
   }

   public function getNumCommentsStr()
   {
    $num = $this->reviews()->count();

    return $num;
   }
}
{{Form::open(数组('url'=>'post/search','method'=>'post','id'=>'search','class'=>'search'))}
{{Form::token()}}
{{Form::text('keyword','',数组('id'=>'keyword','placeholder'=>'keyword'))}
{{表单::提交('提交',数组('class'=>'')}
{{Form::close()}}

我认为问题在于:

{{ Form::open(array('url'=>'post/search','method' => 'post','id'=>'search','class'=>'search'))}}
{{ Form::token()}}
<div class="keywordContainer">
{{Form::text('keyword', '', array('id'=>'keyword', 'placeholder'=>'keyword'))}}
<i class="fa fa-search"></i>
</div>
{{ Form::submit('提交',array('class'=>''))}} 
{{Form::close()}}
尝试用以下方法更改它:

return Redirect::route('searchResults')->with('posts', $posts);
搜索结果中
更改:

return Redirect::route('searchResults')->with('posts', $posts->toArray());
进入:


为了确保问题发生在哪里-在第一个方法中或在重定向后的方法中

我认为问题在这里:

{{ Form::open(array('url'=>'post/search','method' => 'post','id'=>'search','class'=>'search'))}}
{{ Form::token()}}
<div class="keywordContainer">
{{Form::text('keyword', '', array('id'=>'keyword', 'placeholder'=>'keyword'))}}
<i class="fa fa-search"></i>
</div>
{{ Form::submit('提交',array('class'=>''))}} 
{{Form::close()}}
尝试用以下方法更改它:

return Redirect::route('searchResults')->with('posts', $posts);
搜索结果中
更改:

return Redirect::route('searchResults')->with('posts', $posts->toArray());
进入:


为了确保问题发生在哪里-在第一种方法中或在重定向后的方法中

请显示
$关键字的内容
,以及您刚刚添加的
帖子
model@Marcin Nabiałek,谢谢你为什么用这些闪现的结果重定向?请用你的方式显示
$keyword
和你刚刚添加的
Post
model@Marcin Nabiałek的内容,谢谢你为什么用闪现的结果重定向,它显示了searchResults页面中的所有帖子,第一句话类似,之后是所有带有标题和内容的帖子:array(15){[0]=>array(9){[“id”]=>int(1)[“category”]=>string(5)“share”[“title”]=>string(54)”触摸事件,而不是用JavaScript“[“summary”]=>string(116)点击或悬停在本月23日日日的一名名名名为本月23日日的一名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名名“content”=>string(12228)”@franklee,但您是否使用过您的
$posts=Post::where('content','like','%%.$keyword.%'))->返回之前先分页(5);
?我只是做了一个检查,我使用:$posts=Post::where('content','like','%'。$keyword.'%')->get();刚才我想得到我刚才说的。ADD:我尝试了分页(5)来替换get(),看起来是一样的result@franklee因此,再次将其更改为开始时的内容:
$posts=Post::where('content'、'like'、'%.$keyword.'%')->paginate(5);
似乎是相同的结果,我遗漏了什么?通过使用您的方式,它显示搜索结果页面中的所有帖子,其中第一句是like,之后是所有带有标题和内容的帖子:array(15){[0]=>array(9){[“id”=>int(1)[“category”=>string(5)“share”[“title”]字符串(54)“触摸事件取代点击事件而非点击或鼠标悬停的触摸事件”(54)字符串(54)“触摸事件取代点击或鼠标悬停的触摸事件”(54)字符串(116)字符串(54)字符串(54)字符串(54)“触摸事件(116))字符串(116)字符串(116)字符串(116)字符串(116))10))10)10)10)10)字符串(54)弦(54)字符串(54)字符串(54)字符串(54)字符串(116)11)11)10)10)3)日日日,3)日,3)日,3日,3)日,3日,3)日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日,日381.“内容”=>字符串(12228)“@franklee但是你在返回之前是否先使用了你的
$posts=Post::where('content','like','%'.$keyword'.%')->paginate(5);
?我只是做了一个检查,我使用了:$posts=Post::where('content','like',''.%'.$keyword'.%')->get();刚才是为了得到我刚才说的话。添加:我试着用paginate(5)来代替get(),似乎是一样的result@franklee因此,再次将其更改为您在开始时所拥有的内容:
$posts=Post::where('content','like','%'。$keyword.'%')->paginate(5);
似乎是相同的结果,我缺少什么?