我在laravel中包含了一个文件,它给我发了以下错误:
Method Illuminate\View\View::__toString() must not throw an exception
我已将该文件包含在内:
@include('users.opentasks')
我在同一页面上使用了两个包含,但如果我使用一个包含它并没有什么区别。
我不确定这意味着什么以及如何在这里解决这个新手的问题。希望有人可以提供帮助。
我的代码如下:
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
@extends("layout")
@section("content")
@include('users.openprojects')
@include('users.opentasks')
@stop
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
答案 0 :(得分:2)
你可能想这样做:
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);
}