我如何使用laravel来获取用户相关的东西

时间:2017-04-10 09:23:24

标签: php laravel

当One Branch Admin登录并添加药物时,我如何做到这一点,它只在输入字段中显示其自己的分支名称和公司名称,即分支。但是,当我显示所有分支机构和所有与该分支无关的公司名称时。

控制器:

public function getmedicineform(){
        $compny = Company::all();
        $branch = Branch::all()->unique('user_id','=', Auth::user()->id)->uniqueStrict();
        $user = User::where('id','user_id')->whereIn('id', $branch)->get();
        return view("medicinesdetails.addProduct")->with('company', $compny)->with('branch',$branch)->with('user',$user);
    } 

查看:

 <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
    <form class="form-horizontal product-form" action="/add/product" method="post">
        <div class="form-group">
            <label class="col-sm-3 control-label">Company</label>
            <div class="col-sm-9">
                <select class="form-control" name="company_id">
                    <option value="">Select</option>
                    @foreach($company as $compnyy)
                        <option value="{{$compnyy->id}}">{{$compnyy->company_name}}</option>
                    @endforeach
                </select>
                @if($errors->has('company_id'))
                    {{$errors->first('company_id')}}
                @endif
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">Branch</label>
            <div class="col-sm-9">
                <select  class="form-control" name="branch_id">
                    <option value="">Select</option>
                    @foreach($branch as $brnch)
                        <option value="{{$brnch->id}}">{{$brnch->branch_name}}</option>
                    @endforeach
                </select>
                @if($errors->has('branch_id'))
                    {{$errors->first('branch_id')}}
                @endif
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">Medicine-Name</label>
            <div class="col-sm-9">
                <input type="text" class="form-control" name="product_name" placeholder="Product Name">
                @if($errors->has('product_name'))
                    {{$errors->first('product_name')}}
                @endif
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">Medicine-Type</label>
            <div class="col-sm-9">
                <select class="form-control" name="product_type">
                    <option value="">Select</option>
                    <option value="tablet">Tablet</option>
                    <option value="syrup">Syrup</option>
                    <option value="injectable">Injectable</option>
                </select>
                @if($errors->has('product_type'))
                    {{$errors->first('product_type')}}
                @endif
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">Potency</label>
            <div class="col-sm-9">
                <input type="text" class="form-control" name="potency" placeholder="Potency">
                @if($errors->has('potency'))
                    {{$errors->first('potency')}}
                @endif
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">Manufacturer</label>
            <div class="col-sm-9">
                <input type="text" class="form-control" name="manufact" placeholder="manufacturer">
                @if($errors->has('manufact'))
                    {{$errors->first('manufact')}}
                @endif
            </div>
        </div>

        @if(Session::has('message'))
            <div class="form-group">
                <label class="col-sm-3 control-label"></label>
                <div class="col-sm-9">
                    <div class="alert alert-info" role="alert">{{Session::get('message')}}</div>
                </div>
            </div>
        @endif

        <div class="form-group">
            <label class="col-sm-3 control-label"></label>
            <div class="col-sm-9">
                <button type="submit" value="Add product" class="btn btn-default">Submit</button>
            </div>
        </div>
        {{csrf_field()}}
    </form>
    </div>

型号:

class Medicine extends Model
{
    protected $table = 'medicines';
    public function medicine(){
        return $this->hasOne('App\Medicine', 'user_id', 'id');
    }

0 个答案:

没有答案