paras
paras

Reputation: 53

Getting an error in passing a variable through routes to controller in laravel

In app\routes.php Route::get('author/(:any)',array('as'=>'author','uses'=>'AuthorsController@get_view'));

In app\controllers\AuthorsController.php

<?php
class AuthorsController extends BaseController {
public $restful=true;

 public function get_view($id){
  return View::make('authors.view')
->with('title','Author View Page')
->with('author',Author::find($id));
 }

 }

In views\authors\view.blade.php

<!DOCTYPE html>
<html>
<head> <title> {{ $title }}</title> </head>
<body>
<h1> {{$author->name}}</h1>
<p> {{ $author->bio}}  </p>
<p><small>{{$author->updated_at}} <small></p>
</body>
</html>

In a database there is a table named authors containing columns "id", "name", "bio","created_at","updated_at". Also explain me the exact use of 'as'=>'authors' in the above code

Upvotes: 0

Views: 334

Answers (2)

Jason Brodie
Jason Brodie

Reputation: 330

Route should be:

Route::get('author/{id}', array('as'=>'author', 'uses'=>'AuthorsController@get_view'));

Upvotes: 0

Rafael
Rafael

Reputation: 7746

Your route is using old style syntax. In 4.2 use {} in URIs to indicate a variable.

Route::get('author/{id}', array('as' => 'author', 'uses' => 'AuthorsController@get_view'));

Upvotes: 1

Related Questions