Laravel include导致错误:方法Illuminate \ View \ View :: __ toString()不得引发异常 [英] Laravel include causes error: Method Illuminate\View\View::__toString() must not throw an exception

查看:87
本文介绍了Laravel include导致错误:方法Illuminate \ View \ View :: __ toString()不得引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在laravel中包含一个文件,它向我抛出了以下错误:

I'm including a file in laravel and its throwing me the following error:

Method Illuminate\View\View::__toString() must not throw an exception

我已经按原样包含了文件

I've included the file as so:

@include('users.opentasks')

我在同一页面上使用了两个包含,但是如果使用其中一个并没有什么不同.

I'm using two includes on the same page, but if I use one it doesn't make a difference.

我不太确定这是什么意思,以及如何在此处解决此新手问题.希望有人能帮忙.

I'm not really sure what this means and how to fix this bit of a newbie here. Hope someone can help.

我的代码如下:

UserController.php

UserController.php

public function profile() {
     $status = "closed";
    $data["projects"] = $projects = Auth::user()->projects()->where('status', '!=', $status) 
                                ->paginate(4);

    //$data["tasks"] = $tasks = Auth::user()->tasks->paginate(4);

      //  $data["tasks_pages"] = $tasks->links();

        //Comments pagination
        $data["projects_pages"] = $projects->links();


         if(Request::ajax())
            {

            $html = View::make('users.openprojects', $data)->render();
            return Response::json(array('html' => $html));
        //    $html = View::make('users.opentasks', $data)->render();
          //  return Response::json(array('html' => $html));
        }

        echo View::make('users.profile')->with('projects', $projects);

}

public function opentasks() { 

            $user = User::with(array('tasks', 'tasks.status'))->find(Auth::user()->id); 
            return View::make('users.opentasks')->with('user', $user); 

}

profile.blade.php

profile.blade.php

@extends("layout")
@section("content")
@include('users.openprojects')
@include('users.opentasks')
@stop

opentasks.blade.php

opentasks.blade.php

@foreach($user->tasks as $task) 
    {{ $task->task_name }} 
    {{ $task->task_brief}} 
            @if(!is_null($task->status)) 
              {{ $task->status->status_name }}<br/><br/><br/><br/> 
            @endif 
@endforeach

推荐答案

您可能想要这样做:

if(Request::ajax())
{
  // --- this part of the code is odd
  $html = View::make('users.openprojects', $data)->render();
  return Response::json(array('html' => $html));
  // ---
} else {
  $user = User::with(array('tasks', 'tasks.status'))->find(Auth::user()->id); 

  $data = array(
     'user'     => $user,
     'projects' => $projects
  );

  return View::make('users.profile', $data);
}

这篇关于Laravel include导致错误:方法Illuminate \ View \ View :: __ toString()不得引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆