OK what I am trying to do is populate a drop down in a twig view. The options would be numbers 1-12 and 14-17. I need to show only the numbers not active in the database. I am very new to php so I may be trying to do this all wrong. In twig I was trying to do a:
{% if app.user.usernumber1 %}
// if returned true leave blank
{$ else $}
<option value"1">1</option>
{% endif %}
I am sure there is a way to use a for loop of some kind to keep from having to wright the code for each number but for now I am just wanting to make it work. usernumber1 would be a function to test if the number is active. Here is what I was trying.
<?php
namespace Rocmnd\user;
use Illuminate\Database\Eloquent\Model as Eloquent;
class user extends Eloquent
{
protected $table = 'user';
protected $fillable = [
'user_id',
'user_first_name',
'user_last_name',
'active'
];
public function usernumber1()
{
$usernum = $this->user
->where('user_id', 1)
->where('active', true)
->first();
return (bool) $usernum->count();
}
Here is where I have am having problems. I tried to echo out the function and I get a Call to a member function where() on null. when I move the code to the index page it works fine like this.
echo ($app->user
->where('user_id', 1)
->where('active', true)
->first());
Where am i going wrong when I put this into the function?