Support the ongoing development of Laravel.io →
Eloquent Views Blade
Last updated 1 year ago.
0

In your CustomerController you have:

return View::make('dashboard', array('customers', $customers));

It should be:

return View::make('dashboard', array('customers' => $customers));
Last updated 1 year ago.
0

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): ?>
Last updated 1 year ago.
0

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?

Last updated 1 year ago.
0

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.

Last updated 1 year ago.
0

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.

Last updated 1 year ago.
0

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!

Last updated 1 year ago.
0

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>
Last updated 1 year ago.
0

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.

Last updated 1 year ago.
0

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!

Last updated 1 year ago.
0

Hi, you must be careful with your folder schema.

Seeing your exception I found duplicated app folder. Could you post your folders schema?

Thanks.

Last updated 1 year ago.
0

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.

Last updated 1 year ago.
0

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...

Folder structure

Last updated 1 year ago.
0

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.

Last updated 1 year ago.
0

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.

Last updated 1 year ago.
0

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.

Last updated 1 year ago.
0

Try like this:

    Route::get('/dashboard', function() {

             $customers = Customer::all();

             return view('dashboard')->with('customers', $customers);
     });
Last updated 7 years ago.
0

Good job posting on something two years old.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

crippy crippy Joined 22 May 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.