我正在尝试使用数据透视表关系从数据库更改主页文本语言。 所有工作正常,我没有得到任何错误,但登录词不显示。 我有3个表Laravel 5数据透视表不起作用
语言
id | name | sign | default_back
1 | English | en | 1
2 | Russian | ru | 0
功能
id | code | type
70 | login | 0
feature_language
id | feature_id | language_id | text
1 | 70 | 2 | Ru Login
2 | 70 | 1 | Login
语言模型
<?php // Languages Model
namespace App;
use Illuminate\Database\Eloquent\Model;
class Language extends Model
{
public function features(){
return $this->belongsToMany('App\Feature');
}
public function getDefaulLanguage(){
return $this->default_back;
}
public function featureTranslation($code){
return $this->features()->where('code', '=', $code)->first();
}
}
?>
功能特点型号
<?php // Features Model
namespace App;
use Illuminate\Database\Eloquent\Model;
class Feature extends Model
{
}
?>
指数控制器
<?php // index controller
namespace App\Http\Controllers
use App\Language;
class HomeController extends Controller {
public function index(){
$languages = Language::get();
$language_default = Language::where('default_back', '>', '0')->first();
return view('index')->with('languages', $languages)
->with('language_default', $language_default);
}
}
?>
索引视图
<?php
<h1>login : {{ $language_default->featureTranslation("login")->text}}</h1>
?>
任何帮助将不胜感激))
我做了它使用本机mysql –
请解释更多 –
我使用DB :: select(DB :: raw(“SQL QUERY”))来使用本地SQL查询来转换它 –