4

I am a newbie to Laravel. Please excuse me if this question sounds kiddish.

I have a model

class Config extends Eloquent {

    public static $table = 'configs';

}

and the controller goes as

class UserController extends BaseController {

    Public function getIndex ()
    {
        $config_items = Config::all ();
        var_dump ( $config_items );
        return View::make ( 'user.userindex' )
                        -> with ( 'title', 'User Page' );
    }

}

But when i try to access the Config model, i am getting the error:

Symfony \ Component \ Debug \ Exception \ FatalErrorException Call to undefined method Illuminate\Config\Repository::all()

Error Message

Please help!

I know this question could help many Laravel 4 newbies like me and my co-workers, so please help!

0

2 Answers 2

8

As the commenter pointed out, Config is actually a class that's already defined / used.

You have two options:

Option 1:

Namespace your Config model:

<?php namespace My\Models;

use Illuminate\Database\Eloquent\Model;

class Config extends Model { ... }

Then in your controller:

$config_items = My\Models\Config::all();

Note: If you go with option 1 (I suggest you do), you'll need to set up autoloading for your namespaced library. See this blog article on setting up your own Laravel library with autoloading.

Option 2:

Don't use Config as a model name:

<?php

class Configuration extends Eloquent { ... }

Then in your controller:

$config_items = Configuration::all();

Hope that helps!

Sign up to request clarification or add additional context in comments.

Comments

5

I think Config is a reserved keyword used by laravel to manage config files, so please try changing the model name to something else

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.