V
V
Victoria Kabishova2021-08-12 13:46:58
Laravel
Victoria Kabishova, 2021-08-12 13:46:58

How to throw 2 data sets into 1 template?

The code:

<?php
namespace App\Http\Controllers;
use App\Repositories\PageRepository;
use Illuminate\Support\Facades\App;

class PageController extends Controller
{
    public $repository;

    public function __construct(PageRepository $repository)
    {
        $this->repository = $repository;
    }

    public function home()
    {
        $page = $this->repository->forSlug('home');
        abort_unless($page, 404);
        return view('page.simple', compact('page'));
    }

    public function work() 
    {
        $page = $this->repository->forSlug('work'); //2 набора данных, которые нужно прокинуть в  1 шаблон
        $page = $this->repository->forSlug('project');//2 набора данных, которые нужно прокинуть в  1 шаблон
        abort_unless($page, 404);
        return view('page.work', compact('page'));
    }
}

Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Anton, 2021-08-12
@Parsifal31017

$workData = $this->repository->forSlug('work'); //2 набора данных, которые нужно прокинуть в  1 шаблон
        $projectData = $this->repository->forSlug('project');//2 набора данных, которые нужно прокинуть в  1 шаблон
        abort_unless($workData, 404);
        abort_unless($projectData, 404);
        return view('page.work', compact('workData', 'projectData'));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question