首页 > 解决方案 > 从 SQL 表中调用特定值

问题描述

寻求您的帮助我有一个基于 laravel 的网站,我需要对页面提供多语言支持我有以下代码来查看页面:

@extends('web.layout')
@section('content')

<section class="aboutus-content aboutus-content-one">
  <div class="container">
    <div class="heading">
      <h2>
      <?=$result['pages'][0]->name?>
      </h2>
      <hr style="margin-bottom: 10;">
    </div>`
  <?=stripslashes($result['pages'][0]->description)?>     
  </div>

</section>

    @endsection

调用函数

$result['pages'] = DB::table('pages')
                                ->leftJoin('pages_description', 'pages_description.page_id', '=', 'pages.page_id')
                                ->where([['type','2'],['status','1'],['pages_description.language_id',session('language_id')]])
                  ->orwhere([['type','2'],['status','1'],['pages_description.language_id',session('language_id')]])->orderBy('pages_description.name', 'ASC')->get();

数据库是这样的:https ://prnt.sc/rpn9ye

问题是当我切换页面语言时,它不会抓取阿拉伯语,尽管它在数据库中有正确的输入,但它只对我坚持英语。

先感谢您

标签: laravelmodelbalde

解决方案


现在已经解决了

public function getPages($request) { $pages = DB::table('pages') ->leftJoin('pages_description', 'pages_description.page_id', '=', 'pages.page_id') ->where([[ 'pages.status', '1'], ['type', 2], ['pages_description.language_id', session('language_id')], ['pages.slug', $request->name]]) - >orwhere([['pages.status', '1'], ['type', 2], ['pages_description.language_id', session('language_id')], ['pages.slug', $request->名称]]) ->get(); 返回 $pages; }

我已经用直接会话ID替换了一个在orwhere并且它起作用了。


推荐阅读