dongxindu8753 2015-06-30 08:17
浏览 18

根据数据库中的数据填充树枝中的下拉列表

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?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥20 使用Photon PUN2解决游戏得分同步的问题
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM