I have been trying to execute a Method in the User Model after being logged in. It is my understand that you do the following: Auth::user()->foo();
For some reason this is not working.
Code in User.php
<?php
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
use UserTrait, RemindableTrait;
protected $table = 'users';
protected $hidden = array('password', 'remember_token');
public function foo(){
return "foo";
}
}
Code in routes.php
<?php
Route::get('/', function(){
return View::make('hello');
});
Route::get('users', function(){
if (Auth::attempt(array('email' => 'tom@blah.com', 'password' => 'Tom')))echo 'Auth-true';
echo Auth::id();
if(Auth::check())echo 'checked';
Auth::user()->foo();
});
echo Auth::id() and the Auth:check() both work, Auth:user()->foo(); fails
Error Message
Symfony \ Component \ Debug \ Exception \ FatalErrorException
Call to undefined method Illuminate\Auth\GenericUser::foo()