Answer the question
In order to leave comments, you need to log in
Error displaying Laravel category title?
Throws an error when going to the /catalog/{id} route. I tried to display the title of the corresponding category, but apparently I did something wrong, please tell me where the error is.
// Роуты
Route::get('/', '[email protected]');
Route::get('/catalog', '[email protected]');
Route::get('/catalog/{id}', '[email protected]_page');
Route::get('/contacts', '[email protected]');
//Контроллеры
class SiteController extends Controller
{
public function catalog()
{
return view('catalog', ['menus' => Menu::all(),'products' => Tovar::all()]);
}
public function catalog_page($id)
{
$category = new Menu();
$category = $category->with('children')->where('id', $id)->get()->toArray();
return view('catalog_page', ['menus' => Menu::all(),'products' => Tovar::all(),'result' => $category]);
}
public function contacts()
{
return view('contacts', ['menus' => Menu::all(),'products' => Tovar::all(),]);
}
public function index()
{
return view('index',['menus' => Menu::all(),'products' => Tovar::all(),]);
}
}
// Модель Menu
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Menu extends Model
{
protected $table = 'menus';
}
//Вывод заголовка
@extends('template')
@section('content')
<div class="content__right">
<h1>{{$result['title']}}</h1>
</div>
@endsection
Answer the question
In order to leave comments, you need to log in
It's better to immediately accustom yourself to solve such questions correctly
Before displaying the title, look at the contents of $result
First in the view, then inside the function in the controller. More on the situation. I think 5 minutes to solve this issue.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question