Hi everyone
I'm in learning laravel, really a newbie.
It's seems somehow I can't pass the variables from controllers to view.
So this is what I've got
config/route.php
Route::get('/' , "PagesController@link");
Route::get('pg' , "PagesController@link");
Route::get('pg/{link}' , 'PagesController@link');
controllers/PagesController.php
public function link($link = 'index') {
// option 1
return "--->" . $link;
// option 2
return View::make('pages.index' , array('link' => $link));
// option 3
return View::make('pages.index')->with('link', $link);
// option 4
return View::make('pages.index' , compact('link'));
}
views/pages/index.blade.php
@extends('layouts.frontend')
@section('title')
@parent - Index file
@stop
@section('content')
<article>
<header>This is the {{ $link }}</header>
<p>And this is the main body of {{ $link }} file</p>
</article>
@stop
views/pages/layouts/frontend.blade.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>
@section('title')
Lar4 Test
@show
</title>
{{ HTML::style('css/frontend.css') }}
</head>
<body>
<header id="header">
<div id='banner'>
</div>
<nav>
{{ HTML::link('pg' , 'Home') }}
{{ HTML::link('pg/about' , 'About Us') }}
</nav>
</header>
<section>
@yield('content')
</section>
<aside>
</aside>
<footer>
</footer>
</body>
</html>
So if I browse to <site>/pg/sometext only option 1 will work (shows "---->sometext"), all others will thrown an error "Undefined variable: link".
If I comment both {{ $link }}, both layout and index views are successfully rendered.
Any idea of what am I doing wrong?