如何使用左边的条件加入Laravel?

时间:2017-12-28 06:10:21

标签: php laravel-5

我想要检索左侧的所有媒体,如果媒体包含数据,则会填充这些数据。

以下是我的观点:

<tbody>
    <?php $i= 0; ?>
    @foreach($print as $get)
        @if(count($get->media_id)>0 && $get->Status === "Approved")
            <tr>
                <?php   $i++; ?>
                <td style="font-size: 16px; width: 25px; "><?php echo $i; ?></td>
                <td style="font-size: 16px; width: 30px">{{$get->media_name}}</td>
                <td style="font-size: 16px; width: 98px">{{$get->Date_Occured}}</td>
                <td style="font-size: 16px; width: 80px">{{$get->Page_Number}}</td>
                <td style="font-size: 16px; width: 150px">{{$get->Content_title}}</td>
                <td style="font-size: 16px; width: 470px">{!! nl2br(e($get->Content_Description)) !!}</td>
            </tr>
        @endif
    @endforeach
    @foreach($media as  $medias )
        <?php   $i++; ?>
        <tr>
            <td style="font-size: 16px; width: 25px; "><?php echo $i; ?></td>
            <td style="font-size: 16px; width: 30px">{{$medias['media_name']}}</td>
            <td style="font-size: 16px; width: 98px"></td>
            <td style="font-size: 16px; width: 80px"></td>
            <td style="font-size: 16px; width: 150px"></td>
            <td style="font-size: 16px; width: 470px">Hakuna Taarifa kwa Leo</td>

        </tr>
    @endforeach


    </tbody>

这是我的控制器:

public function printpreview() {
    $print = DB::table('media')
       ->leftjoin('content_forms', 'media.id', "=", 'content_forms.media_id')
        ->select('media.*','content_forms.*')
        ->whereDate('content_forms.created_at', DB::raw('CURDATE()'))
        ->get();

    $media = media::all()->toArray();
    return view('pdf.printview', compact('print', 'media'));
}

0 个答案:

没有答案