I've created a model called Hangman. Inside a controller I'm inserting a row in the database like this
$hangman = new Hangman();
$hangman->word = 'exampleWord';
$hangman->lives = 3;
$hangman->save();
So far so good.
I've got two questions:
1) Is it best practice to keep inserting things in the controller?
I assume NO, so I created this method in the model, which I think would be cleaner to call from the controller
public function insert($word, $lives)
{
$hangman = new Hangman();
$hangman->word = $word;
$hangman->lives = $lives;
$hangman->save();
return $hangman;
}
So, my real question (assuming question 1 is NO) is:
2) How would I call this method from the controller?
This doesn't work
\App\Hangman::insert('exampleword', 4);
Namespaces are correct.
I know it's very basic, thanks guys