Click here to Skip to main content
15,887,302 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Sir,

I am using Laravel 5.3 framework.I am just beginner to use laravel, i got an error when i returning variable.

What I have tried:

In routes.php Page
Route::get('users', 'UsersController@show');


In UsersController.php page

 public function show(){

    	$name = 'Naveen';
    	return view('users',['name'=> 'Naveen']);
}


In users.blade.php page

@extends('layout')

@section('content')
	user page {{ $name }}
@stop


Its Returns error

Undefined variable: name (View: C:\xampp\htdocs\diit\resources\views\users.blade.php)

please help me in this
Posted
Updated 26-Jan-17 0:44am

1 solution

Well - I found this for you Views - Laravel - The PHP Framework For Web Artisans[^]

My personal preference is to not use frameworks - you then become dependent upon their existence and your pages/applications/&etc. become unusable or you become a prisoner of the frameworks and it's whims.

I will note the following for you:
Undefined variable: name (View: C:\xampp\htdocs\diit\resources\views\users.blade.php).

Note the upper-case "V' in View. The PHP language is case-sensitive. If you've done that somewhere in your apllication then you are getting a error since view()  != View()  

UPDATE: alternatively, the variable in question is '$name', and this may be a scope problem: name defined, for example, in a function and then an attempt to use it is made outside of the function (or class, or a failure to use proper 'include' statements.
 
Share this answer
 
v3
Comments
Jochen Arndt 26-Jan-17 6:53am    
I think that "View" is part of the error message here with the meaning to have a look at the mentioned file:

Undefined variable: Error message
name: The undefined variable
(View: *.php): Suggested action
Naveen Roy 28-Jan-17 4:24am    
if you don't know about codeIgnighter and Laravel then don't suggest me to don't use it.
W Balboos, GHB 30-Jan-17 6:16am    
Trying to help you so you learn how to code and won't find yourself in the predicament that you have trouble with something as basic as "undefined variable". It is your choice and privilage to wallow in helpless ignorance as long as wish.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900