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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog