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()
Please help!
I know this question could help many Laravel 4 newbies like me and my co-workers, so please help!
As the commenter pointed out, Config
is actually a class that's already defined / used.
You have two options:
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.
Don't use Config
as a model name:
<?php
class Configuration extends Eloquent { ... }
Then in your controller:
$config_items = Configuration::all();
Hope that helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With