Help me display a specific array element in Laravel 5.4

In short, here are the routes (web.php)

Route::name('admin::')->prefix('admin')->group(function(){ //Авторизация Route::name('auth::')->prefix('auth')->group(function(){ Route::name('view')->get('view', 'Admin\DashboardController@auth'); Route::name('act')->post('act', 'Admin\DashboardController@auth'); Route::name('logout')->get('logout', 'Admin\DashboardController@logout'); }); Route::name('home')->get('home', 'Admin\DashboardController@home'); Route::name('content::')->prefix('content')->group(function(){ Route::name('page::')->prefix('page')->group(function(){ Route::name('list')->get('list', 'Admin\DashboardController@list'); Route::name('about')->get('about', 'Admin\DashboardController@about'); 

Method in controller (DashboardController @ about)

  public function about() { return view('upgr.static.about', [ 'dashboards' => Dashboard::orderBy('id')->paginate(16), 'dashboard' => [], 'delimiter' => '' ]); } 

File about

 @section('content') <main> <div class="container"> <ol class="breadcrumbs"> <li class="breadcrumbs-item"><a href="/">Главная</a></li> @forelse($dashboards as $dashboard) <li class="breadcrumbs-item">{{ $dashboard->name }}</li> </ol> </div> <div class="container"> <h1>{{ $dashboard->title }}</h1> <p>{!! $dashboard->description !!}</p> <img src="{{ $dashboard->image }}" alt="{{ $dashboard->name}}" class="img-responsive"> @empty <h2>Скоро здесь появиться информация, пожалуйста подождите.</h2> @endforelse </div> </main> @endsection 

In this scenario, on my site, all data from the database is displayed by itself. enter image description here

Sori everyone who cuts my eyes)

According to my assumptions, instead of a cycle, you need to set a condition and change the first line in the controller, but what I did not try to do did not work.

The question is how can I make it so that the tab "About the company" displays data with id = 2, id = 3 in the "Contacts", etc.?


P. s. I changed the method in the controller to

  public function about() { return view('upgr.static.about', [ 'dashboard' => Dashboard::orderBy('id')->get()->first(), 'delimiter' => '' ]); } public function kontakt() { return view('upgr.static.kontakt', [ 'dashboard' => Dashboard::orderBy('id')->get()->first(), 'delimiter' => '' ]); } 

Also changed two files about and kontakt

about.blade.php:

 @section('content') <main> <div class="container"> <ol class="breadcrumbs"> <li class="breadcrumbs-item"><a href="/">Главная</a></li> @if($dashboard['id'] == 2) <li class="breadcrumbs-item">{{ $dashboard->name }}</li> </ol> </div> <div class="container"> <h1>{{ $dashboard->title }}</h1> <p>{!! $dashboard->description !!}</p> <img src="{{ $dashboard->image }}" alt="{{ $dashboard->name}}" class="img-responsive"> @endif </div> </main> @endsection 

shows this, all okay, I wanted to enter image description here

kontakt.blade.php

 @section('content') <main> <div class="container"> <ol class="breadcrumbs"> <li class="breadcrumbs-item"><a href="/">Главная</a></li> @if($dashboard['id'] == 3) <li class="breadcrumbs-item">{{ $dashboard->name }}</li> </ol> </div> <div class="container"> <h1>{{ $dashboard->title }}</h1> <p>{!! $dashboard->description !!}</p> <br><br><br> @endif </div> </main> @endsection 

shows nothing enter image description here

Why? Everything is identical and it would seem that the id has changed. There should be another infa from the database, no?

  • The eyes do not cut the issue and the color of the code, bright green on a black background X_X - Manitikyl
  • @Manitikyl on monitor settings may depend. but in any case, the code - the text is necessary and not pictures - teran
  • I apologize, I will consider next time. And now I'll edit the code. - Sepol am
  • @teran I have a regular monitor like everyone else, I don’t think that someone was sitting and turning himself green, so that later in the editor I could make it brighter to see the code normally. - Manitikyl
  • I'm not saying that someone twisted the green. it is rather one of the standard schemes, which, together with a tired monitor and the author’s poor eyesight, is perhaps quite comfortable for him. - teran

1 answer 1

Your page data is in the dashboard, try

 'dashboard' => Dashboard::find(3) 

for about page. The three will need to be replaced in each controller with the desired partition ID.