I'm using lumen from laravel 5.2 and edit app_key and database info in .env file also uncomment $app->withFacades(); in bootstrap/app.php so now i can connect to my database.
the problem is i want to use model in my project but always failed.
my model store in app/Models/User.php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class User extends Model {
protected $table = 'user';
protected $fillable = ['userid','name','timestamp'];
}
my controller
namespace App\Http\Controllers;
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Request-With');
header('Access-Control-Allow-Credentials: true');
use Illuminate\Http\Request;
use Laravel\Lumen\Routing\Controller as BaseController;
use DB;
use App\Models\User;
class Controller extends BaseController
{
public function tes(Request $request){
$user = User::where('id','=',1)->first();
return 'name: '.$user->name;
}
}
i also tried change
use App\Models\User;
with
use App\User;
but still not working.
here my error message
FatalErrorException in Model.php line 3280:
Call to a member function connection() on null
in my xampp server there is also this message
Fatal error: Call to a member function connection() on null in D:\Workspace\website\api\vendor\illuminate\database\Eloquent\Model.php on line 3280
what i have tried
- edit database.php in lumen-framework/config/
- copy and put database.php in app/Config/
and still not working. is there something i miss?