Starting Blade Templating in laravel 5

In the following example we are creating our first example with blade template engine.

Directory structure

Untitled

Route file (routes.php)

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

Route::get('/', 'WelcomeController@index');

// this is the auth controller
Route::resource('auth', 'Authors_Controller@index');

Controller file (Authors_Controller.php)

<?php namespace App\Http\Controllers;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class Authors_Controller extends Controller {

	/**
	 * Display a listing of the resource.
	 *
	 * @return Response
	 */
	public function index()
	{
		// here we are defining array
		return view('authors.index', array(
										'name' => 'abc',
										'company' => 'abcCompany',
										'address' => 'xyz'
										  )
		);
	}
}

Views file(index.blade.php)

<h1>Data display</h1>

{{ $name }} <br>
{{ $company }} <br>
{{ $address }} <br>

Output

Data display
abc
abcCompany
xyz

Share

You may also like...