php - Route [name] not defined in laravel 4.1 -
i have problem within routes , variable. need pass variable in foreach loop routes. here error meesage "route [patientname] not defined". here homepage.blade.php:
@foreach($patientslist $patients) <tr> <td>{{ $patients->name }}</td> <td>{{ $patients->email }}</td> <td>{{ $patients->address }}</td> <td>{{ $patients->phone_number }}</td> <td>{{ $patients->type }}</td> <td><a href="{{ url::route('patientname', array('pname' => $patients->name)) }}" class="view-profile">view profile</a></td> </tr> @endforeach
routes.php:
route::get('patientname/{pname}','patientscontroller@getpatientname');
controller
<?php class patientscontroller extends basecontroller{ /*some functions*/ function getpatientname($patientname){ return $patientname; } }
solution 1
url::route
generates link named route - expects route's name parameter. in code, not specify route's name, url helper cannot generate link , throws route not found error. check corrections below
//routes.php - specify route's name route::get('patientname/{pname}', array('as'=>'patientname', 'uses'=>'patientscontroller@getpatientname'));
now can safely use
<a href="{{ url::route('patientname', array('pname' => $patients->name)) }}" class="view-profile">view profile</a>
important: remember run composer dump-autoload
after modify routes.php file.
solution 2
on other hand, can change method url generation , use url::to
. expects parameter containing path.
<a href="{{ url::to('patientname/'.$patients->name) }}" class="view-profile">view profile</a>
conclusion refer documentation details on different ways of safe url generation based on routes
http://laravel.com/docs/routing
also sure check url helper docs useful stuff
http://laravel.com/docs/helpers#urls
Comments
Post a Comment