user0129e021939232
user0129e021939232

Reputation: 6355

Laravel include causes error: Method Illuminate\View\View::__toString() must not throw an exception

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.

My code is as follows:

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

Upvotes: 2

Views: 2987

Answers (1)

majidarif
majidarif

Reputation: 20025

You might want to do it like this:

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);
}

Upvotes: 2

Related Questions