NooBskie NooBskie -4 years ago 37
PHP Question

How to render view template via controller

I want to reuse the same

return View::make('pages.home');
template view for my
but I am not sure how to connect the view to that controller.

I am assuming I need to put something in my
of my controller but I am not exactly sure what as this is my first time with Laravel.

Here is my current code:



Route::get('/home', function () {
return View::make('pages.home');

Route::get('/', 'UserController@index');
Route::get('user/{id}', 'UserController@show');

Route::get('/foo', function () {
return 'taobao';

UserController.php //simplified

public function index()
return view('user', ['name' => 'James']);

Answer Source

If you need to reuse the same return View::make('pages.home'); or home view in your UserController you can call it as

return view('home', ['name' => 'James']);

or you need to include home view in users view then you can do

@extends('home') or @include('home')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download