Есть 2 таблицы: PHP: <?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateSlidestructsTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('slidestructs', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('number'); $table->string('title', 2000); $table->integer('title_sign'); $table->string('category', 2000); $table->string('slidestructs_image_url', 2000); $table->string('slidestructs_thumb_url', 2000); $table->integer('thumb_position')->nullable(); $table->string('type', 100); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('slidestructs'); } } PHP: <?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateSlideimagesTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('slideimages', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('slide_id'); $table->foreign('slide_id')->on('slidestructs')->references('id'); $table->string('slideimages_image_url', 2000); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('slideimages'); } } Контроллер: PHP: <?php namespace App\Http\Controllers; use App\Http\Resources\SlideResource; use App\Slidestruct; use Illuminate\Http\Request; class PresentationController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $Struct = Slidestruct::with('slideimage')->get(); return SlideResource::collection($Struct); } И в api.php: PHP: Route::get('/', '\App\Http\Controllers\PresentationController@index'); Файл slide.php: PHP: <?php namespace App\Http\Resources; use Illuminate\Http\Resources\Json\JsonResource; class Slide extends JsonResource { /** * Transform the resource into an array. * * @param \Illuminate\Http\Request $request * @return array */ public function toArray($request) { //return parent::toArray($request); } } Файл SlideResource.php: PHP: <?php namespace App\Http\Resources; use App\Slidestruct; use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Http\Resources\Json\ResourceCollection; class SlideResource extends JsonResource { /** * Transform the resource into an array. * * @param \Illuminate\Http\Request $request * @return array */ public function toArray($request) { return [ 'id' => $this->id, 'number' => $this->number, 'title' => $this->title, 'title_sign' => $this->title_sign, 'category' => $this->category, 'slidestructs_image_url' => $this->slidestructs_image_url, 'slidestructs_image_thumb' => $this->slidestructs_image_url, 'thumb_position' => $this->thumb_position, 'type' => $this->type, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'slideimages_image_url' => Slide::collection($this->slideimages_image_url), ]; } } выдает ошибку: "Call to a member function first() on null", хочу вытащить связанные данные с помощью кода: PHP: 'slideimages_image_url' => Slide::collection($this->slideimages_image_url),