doudichu1358 2017-01-02 22:56
浏览 69

在laravel检查这个?

I am developing a roleplay game. Below I have a controller for the government. What I am trying to do is to get a list of the higher government members, senior government members, and the junior government members (these are a different type of government members) for example...

Here is my database structure

  • Junior Government would be the Ministers
  • Senior Government would be the Secretary of States
  • Higher Government would be the Prime Minister and The Crown

I have a table for roleplay statistics called srp_rp_stats and in there I have a column called government_id which is meant to match the id in the government table.

In my government table, I have an id field as the primary key, a title for the government position, and the type it is. The type field is an enum, example below...

government_type enum
'higher_government','senior_government','junior_government'

What I want to do below is to get the members of each of the set of governments, but I need to use the government_id in the rp table to check that in the government table the type is actually what I am looking for, how can I do this?

Code:

namespace App\Http\Controllers\Frontend\User;

use Auth;
use Cache;
use Illuminate\Http\Request;
use App\Database\Website\Roleplay\Life\LifeEvents;

class GovernmentController
{
    public function getView()
    {
        $higherGovernment = Cache::remember('government.higher_government', function() {
            return Roleplay::get();
        });

        $seniorGovernment = Cache::Remeber('government.senior_government', function() {
            return Roleplay::get();
        });

        $juniorGovernment = Cache::remember('government.junior_government', function () {
            return Roleplay::get();
        });

        return view('frontend.community.government', compact('higherGovernment', 'seniorGovernment', 'juniorGovernment'));
    }
}
  • 写回答

2条回答 默认 最新

  • dousui4577 2017-01-03 08:47
    关注

    I think your better off using Eloquent for this, not sure what version or Laravel your doing this on but here is the guide for 5.3 Eloquent: https://laravel.com/docs/5.3/eloquent

    $higherGovernment = Goverment::where('government_type', 'higher_government')->get();
    

    This will give you all of the entries that have 'Higher Government' in the type field.

    评论

报告相同问题?

悬赏问题

  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误