When using the Laravel helper view what kind of data is being returned?

2

I'm hesitant to comment on the method below:

public function index()
{
    $posts = Post::orderBy('created_at', 'desc')->paginate(10);

    return view('painel.post.listar', compact('posts'));
}

It would be correct to comment this way:

/**
 * Retorna uma instância de View
 * 
 * @return object
 */
public function index()
{
    $posts = Post::orderBy('created_at', 'desc')->paginate(10);

    return view('painel.post.listar', compact('posts'));
}

Or the return would be View and in the description instead of " Return an instance of View " would be "Return an object" / p>     

asked by anonymous 10.11.2016 / 02:40

2 answers

1

A pattern used by the looks like this:

/**
 * Return Instance of View.
 * 
 * @return Illuminate\View\View
 */
public function index()
{
    $posts = Post::orderBy('created_at', 'desc')->paginate(10);

    return view('painel.post.listar', compact('posts'));
}

The helper view returns the instance of the class Illuminate\View\View . / p>     

10.11.2016 / 03:04
2

The initial description is perfect, it returns an instance of the View so the return is a View.

Note that the view is nothing more than an object responsible for rendering htmls.

Note also that in the documentation of laravel we have some examples of using and creating the view, below:

$view = View::make('greetings', $data);

Note that the view has its own methods, such as the share that is responsible for sharing snippets from within a view as below:

 View::share('name', 'Steve');

If you repair the view's own creation in the first part of the demonstration, it clearly demonstrates that we are creating a View object type. see in $ view = View :: make ....

    
10.11.2016 / 03:08