在laravel 5.5中我的视图的不同部分调用控制器

时间:2017-11-29 14:13:41

标签: php laravel laravel-views

我想从我的视图中调用多个控制器路径,并在我的站点的不同部分显示他们的数据。

x<body>
<nav class="navbar navbar-fixed-top navbar-inverse">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">HR Lead</a>
        </div>
        <div id="navbar" class="collapse navbar-collapse">
            <ul class="nav navbar-nav">
                <li class="active"><a href="#">Home</a></li>
                <li><a href="#about">About</a></li>
                <li><a href="#contact">Contact</a></li>
            </ul>
        </div><!-- /.nav-collapse -->
    </div><!-- /.container -->
</nav><!-- /.navbar -->

<div class="container">

    <div class="row row-offcanvas row-offcanvas-right">

        <div class="col-xs-12 col-sm-9">
            <p class="pull-right visible-xs">
                <button type="button" class="btn btn-primary btn-xs" data-toggle="offcanvas">Toggle nav</button>
            </p>
            <div class="jumbotron">
                <h1>{{auth()->user()-> name}}</h1>
                <h1>{{auth()->user()-> id}}</h1>
                <p>{{auth()->user()-> position}}</p>
                <p>{{auth()->user()-> company ->name}}</p>
                <p>{{auth()->user()-> job_post}}</p>
            </div>
                    <div class="row">
                        <?php $user= users::find(auth()->user()) ?>

                        @foreach($user-> job_post as $job_post )
                        <div class="col-xs-6 col-lg-4">
                            <h2>{{$job_post->title}}</h2>
                            <p>{{$job_post-> summary }} </p>
                            <p><a class="btn btn-default" href="#" role="button">View details »</a></p>
                        </div>

                        @endforeach

但它返回

  

错误:&#34;班级&#39;用户&#39;找不到&#34;

我尝试了不同的事情,但没有成功。

1 个答案:

答案 0 :(得分:0)

您必须使用名称空间,可能类似于:

<?php $user = App\Model\Users::find(auth()->user()) ?>