Всех с праздниками!
Прощу помощи в получение значения поля в Laravel.
Первая миграция:
Schema::create('addresses', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->text('address')->nullable(true);
});
Вторая миграция:
Schema::create('organizations', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->text('name');
$table->integer('inn');
$table->integer('address');
});
Schema::table('organizations', function (Blueprint $table) {
$table->foreign('address')
->references('id')
->on('addresses')
->onDelete('cascade');
});
Контроллер:
return organizations::with('address')->limit(10)->get() ;
Модель получения данных:
return $this->hasOne(addresses::class,'id','address')->select('address','id');
В итоге получаю ответ:
[{"id":2,"created_at":"2021-01-02T10:43:44.000000Z","updated_at":"2021-01-02T10:43:44.000000Z","name":"Braun Ltd","inn":5<b>,"address":{"address":"8702 Hosea Freeway Suite 266","id":260}}</b>,{"id":3,"created_at":"2021-01-02T10:43:44.000000Z","updated_at":"2021-01-02T10:43:44.000000Z","name":"Gusikowski, Bartell and Dickens","inn":1,"address":{"address":"2685 Cronin Lakes Apt. 633","id":534}},{"id":4,"created_at":"2021-01-02T10:43:44.000000Z","updated_at":"2021-01-02T10:43:44.000000Z","name":"Crona Group","inn":2,"address":{"address":"124 Leannon Mall","id":820}},{"id":5,"created_at":"2021-01-02T10:43:44.000000Z","updated_at":"2021-01-02T10:43:44.000000Z","name":"Cormier-Durgan","inn":6,"address":{"address":"21222 Lueilwitz Light","id":202}},{"id":6,"created_at":"2021-01-02T10:43:44.000000Z","updated_at":"2021-01-02T10:43:44.000000Z","name":"Rodriguez-Shanahan","inn":0,"address":{"address":"867 Harris Extension Apt. 010","id":374}},{"id":7,"created_at":"2021-01-02T10:43:44.000000Z","updated_at":"2021-01-02T10:43:44.000000Z","name":"Shields Ltd","inn":0,"address":{"address":"78427 Myron Causeway","id":139}},{"id":8,"created_at":"2021-01-02T10:43:44.000000Z","updated_at":"2021-01-02T10:43:44.000000Z","name":"Torp Group","inn":5,"address":{"address":"8316 Frederique Roads","id":580}},{"id":9,"created_at":"2021-01-02T10:43:44.000000Z","updated_at":"2021-01-02T10:43:44.000000Z","name":"Morar, Block and Mante","inn":4,"address":{"address":"29573 Howell Club","id":444}},{"id":10,"created_at":"2021-01-02T10:43:44.000000Z","updated_at":"2021-01-02T10:43:44.000000Z","name":"Torp-Stamm","inn":0,"address":{"address":"869 Heathcote Village","id":424}},{"id":11,"created_at":"2021-01-02T10:43:44.000000Z","updated_at":"2021-01-02T10:43:44.000000Z","name":"Ankunding, Klein and Volkman","inn":2,"address":{"address":"72871 Yundt Pine","id":420}}]
И в адресе получаю объект, а мне надо что бы значения было просто "address":"72871 Yundt Pine".
Если в запросе:
return $this->hasOne(addresses::class,'id','address')->select('address','id');
из select убираю id, то значение возвращается NULL.
Не могу понять как это сделать правильно и оптимально.