F
F
feniksdv2020-09-10 18:03:24
Laravel
feniksdv, 2020-09-10 18:03:24

How to merge requests in Laravel?

Good day.

I am studying laravel and faced such a problem that only 2 variables can be passed through return view, an error pops up on the 3rd one.

The question is how to pass three variables or how to combine queries into one.

Controller

public function showSite($site){
        //в шаблоне не видно, но он подгружается через auth.layouts.app_auth
        $insertSite = ['dataSite' => AddProject::distinct()
                                                ->where('user_id', Auth::id())
                                                ->get(['site'])];

        $rezult = ['dataSiteOne' =>AddProject::where('site', $site)
                                            ->first('site')];

        $table = ['table' => AddProject::where('user_id', Auth::id())
                                        ->where('site', $site)
                                        ->pluck('date')];
        
        return view ('auth.show-site', $insertSite, $rezult, $table);
    }

Sample
@extends('auth.layouts.app_auth')
@section('title')Статистика по проекту — {{$dataSiteOne->site}}@endsection
@section('content')
    <h1>Статистика по проекту — {{$dataSiteOne->site}}</h1>
    @foreach($table as $el)
    <p>Дата — {{$el}}</p>
    @endforeach
@endsection

Route
Route::get('/show/{site}', '[email protected]')->name('show-site');

Mistake
5f5a409d3cb8a886453817.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rst630, 2020-09-10
@feniksdv

return view ('auth.show-site', compact('insertSite', 'rezult', 'table'));

do this and all variables will be passed to the template

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question