In your CustomerController you have:
return View::make('dashboard', array('customers', $customers));
It should be:
return View::make('dashboard', array('customers' => $customers));
gstjohn, it still throws an error
ErrorException Undefined variable: customers (View: /Users/marks-c1/Sites/nit/app/app/views/dashboard.blade.php)
31 <?php foreach($customers as $customer): ?>
Right, stupid question time - got any customers in the database?
What happens the line after $customers = Customer::all(); you drop in dd($customers); ?
Can you see any data?
Chris - Yes there is customers within my customer table, 2 entries of test data. I dropped in dd($customers); after $customers = Customer::all();. This did not return any data...
Customer table consists of (id, address, city, postcode, phone, mobile, contact,user_id, name, updated_at, created_at)
On a note if I comment out all my routes and do the following I get an associative array with all the values, which I would expect too see, but once my routes have been enabled again, I get undefined variable
Route::get('/', function() {
$customers = Customer::all();
return $customers;
}
This is what I get from the above route returning $customers
[{"id":1,"address":"795 Folsom Ave, Suite 600","city":"San Francisco","postcode":"CA 9410","phone":"(123)456-7890","mobile":"(123) 456-7890","contact":"Andrew Ellis","user_id":9,"name":"Direct Furniture","updated_at":null,"created_at":"2014-05-13 23:16:12"},{"id":2,"address":"919 Folsomb Ave, Suite 505","city":"New York","postcode":"NY 9510","phone":"(123)456-7890","mobile":"(123) 567-8901","contact":"Dean Ryan","user_id":9,"name":"Etto","updated_at":null,"created_at":"2014-05-13 23:16:12"}]
But once I enable all routes like first posted, thats when I get an Undefined Variable.
Try using the with function within the View Facade:
return View::make('dashboard')->with('customers', $customers);
Another thing is your dashboard contained in a subview folder? Then you could need to use the dot schema to access to your views.
return View::make('admin.dashboard')->with('customers', $customers);
Hope it helps you.
codeATbusiness
Route::get('/dashboard', function() {
$customers = Customer::all();
return View::make('dashboard')->with('customers', $customers);
});
this now shows all customers, holy sh1t, amazing leap forward, but when I enable the rest of my views I get the error again... Painful, but thanks a mill, I have been at this loads and that is seriously amazing to see!
Hold on its throwing up
ErrorException
Route [account-logout] not defined. (View: /Users/marks-c1/Sites/nit/app/app/views/layout/navigation.blade.php) (View: /Users/marks-c1/Sites/nitt/app/app/views/layout/navigation.blade.php) (View: /Users/marks-c1/Sites/nit/app/app/views/layout/navigation.blade.php)
navigation view
<li><a href="">About</a></li>
@if(Auth::check())
<li class="visible-xs"><a href="{{ URL::route('account-logout') }}">Logout</a></li>
<li class="visible-xs"><a href="{{ URL::route('account-change-password') }}">Change Password</a></li>
@else
<li class="visible-xs">{{ HTML::link('account/register', 'Register') }} </li>
<li class="visible-xs"><a href="{{ URL::Route('account-login') }}">Login</a></li>
You must be careful if you use REST controllers and later you link routes to drivers on an individualy since you could overlap the routing.
I am glad to see that you can see your customers.
instead of URL::Route is it wiser to do {{ HTML::link('account/register', 'Register') }} ? Why is that codeATbusiness? Thanks again, you have concluded 16hrs of searching high and low!
Hi, you must be careful with your folder schema.
Seeing your exception I found duplicated app folder. Could you post your folders schema?
Thanks.
Friend, you are welcome!
I think you talk about the moment you named the routes with the 'as' array key you are naming this routes, and then you can use this name to get access to the routes.
Hope it helps you.
folder schema
nit > app > app - -commands -config -controllers -database -lang -models -start -tests -views bootstrap public vendor
not sure if theres an easier way to do that for you...
I would create something as follow:
App
- YourAppName
- Entity1
- Repositories
- ServicesProviders
- Entity1Model.php
- Entity2
- Repositories
- ServicesProviders
- Entity2Model.php
- EntityN
- Repositories
- ServicesProviders
- EntityNModel.php
- Services
- Helpers
- Validators
- Handlers
- Exceptions
- ... another yourapp folder
- Commands
- Controllers
- Config
- Lang
- ... other general laravel folders
This is only for sample, you could use it or adapt to your needs, but I would not duplicate the app folder for avoid errors related with the app main container.
You could get more knowledge about the Laravel project organization reading the Taylor Otwell ebook: https://leanpub.com/laravel
Hope it helps you.
codeAtbusiness thanks very much for the help and the others who suggested means of ways. Appreciate all the help. I will take a look into Taylor Otwell ebook, thanks for the recommended reading! Thank you sir.
crippy said:
codeAtbusiness thanks very much for the help and the others who suggested means of ways. Appreciate all the help. I will take a look into Taylor Otwell ebook, thanks for the recommended reading! Thank you sir.
You are welcome! All you need ask here and we help you as soon as possible.
Try like this:
Route::get('/dashboard', function() {
$customers = Customer::all();
return view('dashboard')->with('customers', $customers);
});
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community