-
-
Notifications
You must be signed in to change notification settings - Fork 171
Closed
Description
Describe the bug
I am making a Query with Joins . When I want to response translated columns in API they converting to null values.When I hide $translatedAttributes in the model everything works well. Or selecting the columns with an alias for example name as n it returns the value.
To Reproduce
My Database Schema
pages table:
Schema::create('pages', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('slug');
$table->integer('status');
$table->string('type')->nullable();
$table->timestamps();
});
page_translations table:
Schema::create('page_translations', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('page_id')->unsigned()->index();
$table->foreign('page_id')->references('id')->on('pages')->onDelete('cascade');
$table->string('locale');
$table->string('name');
$table->longText('text');
$table->timestamps();
});
My Page Model:
class Page extends Model
{
use \Astrotomic\Translatable\Translatable;
public $translatedAttributes = ['name','text'];
protected $fillable = ['slug','status'];
public function page_meta()
{
return $this->hasMany('App\Models\Page\PageMeta');
}
public function getDocumentLinkAttribute()
{
return $this->page_meta()->first()->meta_value;
}
}
PageTranslations model class
PageTranslation extends Model
{
public $timestamps=false;
protected $fillable = ['name','text','status'];
}
My codes :
protected $pageModel;
public function __construct(Page $page)
{
$this->pageModel = $page;
}
public function getApiWithType($type)
{
return $this->pageModel->leftJoin('page_translations','pages.id','=','page_translations.page_id')->where('page_translations.locale','az')->where('pages.type','page')->get();
}
Expected behavior
I am making a Query with Joins. When I want to response translated columns in API they converting to null values.When I hide $translatedAttributes in the model everything works well. Or selecting the columns with an alias for example name as n it returns the true value.
Versions
- PHP: 7.2.11
- Database: Mysql
- Laravel: 5.8
- Package: