-1

I try to use the Eloquent without using Laravel in my project and I'm getting this error

Uncaught Error: Call to a member function connection() on null

When I try to call some Eloquent methods.

For example the create method in my createTask function

<?php

class HomeController extends Controller{

    protected $task;

    public function __construct(){
        $this->task = $this->setModel("Task");
    }

    public function index($name = ""){
        $task = $this->task;
        $task->username = $name;

        $this->setView("home/index", ["name" => $task->username, "email" => $task->email] );

    }

    public function createTask($username = "", $email = "", $task = "")
    {
        $this->task->create([
            "username" => $username,
            "email" => $email,
            "task" => $task
        ]);
    }

}

?>

Routing works good, so here is the Model

<?php

use Illuminate\Database\Eloquent\Model as Eloquent;

class Task extends Eloquent
{
    protected $fillable = ["username", "email", "task"];
}

?>

What Am I doing wrong? All the connection values are correct too

<?php

use Illuminate\Database\Capsule\Manager as Capsule;

$capsule = new Capsule;

$capsule->addConnection([
    'driver' => 'mysql',
    'host' => 'localhost',
    'username' => 'root',
    'password' => '',
    'database' => 'todomvc',
    'charset' => "utf8",
    'collation' => 'utf8_unicode_ci',
    'prefix' => ''
]);

$capsule->bootEloquent();

?>

1 Answers1

-1

You made a mistake in your namespace by typing Capluse instead of Capsule

use Illuminate\Database\Capluse\Manager as Capsule;
Shizzen83
  • 3,325
  • 3
  • 12
  • 32