Может шить, чтобы выяснить, в чем проблема, модель не возвращает никаких данных, я должен проверить контроллер, представление, маршрут и все, кажется, в порядке.
public function edit(TrainingCategory $trainingCategory)
{
return view('admin.trainingcategories.edit')->with(['trainingcategory'=>$trainingCategory]);
}
Вот мой метод контроллера , $ trainingCategory не возвращает необходимые данные из базы данных.
Route::prefix('admin')->middleware('is_admin')->group(function () {
Route::get('/dashboard', 'HomeController@adminHome')->name('admin.home');
Route::resource('positions', 'PositionsController');
Route::resource('departments', 'DepartmentsController');
Route::resource('trainings', 'TrainingsController');
Route::resource('trainingcategories', 'TrainingCategoriesController');
Route::get('/trainingcategories/{id}/{action}', 'TrainingCategoriesController@changestatus')->name('trainingcategories.status');
});
Вот мой файл маршрута с кодом
@extends('layouts.admin')
@section('content')
<div class="app-main__inner">
<div class="app-page-title">
<div class="page-title-wrapper">
<div class="page-title-heading">
<div class="page-title-icon">
<i class="pe-7s-user icon-gradient bg-mean-fruit">
</i>
</div>
<div>Edit Training Category
<div class="page-title-subheading">Modify.
</div>
</div>
</div>
<div class="page-title-actions">
<div class="d-inline-block dropdown">
<a href="{{ route('trainingcategories.create') }}" type="button" class="btn-shadow btn btn-info">
Create New Training Category
<span class="btn-icon-wrapper pr-2 opacity-7">
</span>
</a>
<a href="{{ route('trainingcategories.index') }}" type="button" class="btn-shadow btn btn-primary">
List Training Categories
<span class="btn-icon-wrapper pr-2 opacity-7">
<i class="fa fa-arrow-right fa-w-20"></i>
</span>
</a>
</div>
</div>
</div>
</div>
<!--Data table section-->
<div class="row">
<div class="col-md-12">
<nav class="" aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ route('admin.home') }}">Dashboard</a></li>
<li class="breadcrumb-item"><a href="{{ route('trainingcategories.index') }}">Training Category</a></li>
<li class="active breadcrumb-item" aria-current="page">Edit Training Category</li>
</ol>
</nav>
<!--alerts-->
@if(!empty($errors->all()) )
<div class="alert alert-danger fade show" role="alert">
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</div>
@endif
<!--end alerts-->
<div class="main-card mb-3 card">
<div class="card-body"><h3 class="h4">Edit Training Category > <b>{{ $trainingcategory->name }}</b><br>
<small class="muted">Modify</small></h3>
<hr>
<form class="needs-validation" novalidate method="POST" action="{{ route('trainingcategories.update',['trainingcategory'=>$trainingcategory->id]) }}">
@csrf
@method('PUT')
<div class="department-relative form-group">
<label for="name" class="">Name</label>
<input name="name" id="name" placeholder="Enter training category" type="text" class="form-control"
value="{{ old('name',$trainingcategory->name) }}" required>
<div class="valid-feedback">
Looks good!
</div>
<div class="invalid-feedback">
Please enter training category.
</div>
</div>
<div class="department-relative form-group">
<label for="description" class="">Active<i class="muted"></i></label>
@include('includes._active_select')
</div>
<div class="department-relative form-group">
<label for="description" class="">Training Description<i class="muted">(Optional)</i></label>
<textarea name="description" id="description" class="form-control" required> {{ old('description',$trainingcategory->description) }} </textarea>
<div class="valid-feedback">
Looks good!
</div>
<div class="invalid-feedback">
Please enter training description.
</div>
</div>
<button class="mt-1 btn btn-primary">update</button>
</form>
</div>
</div>
</div>
</div>
<!-- form validation-->
<script>
// Example starter JavaScript for disabling form submissions if there are invalid fields
(function() {
'use strict';
window.addEventListener('load', function() {
// Fetch all the forms we want to apply custom Bootstrap validation styles to
var forms = document.getElementsByClassName('needs-validation');
// Loop over them and prevent submission
var validation = Array.prototype.filter.call(forms, function(form) {
form.addEventListener('submit', function(event) {
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
});
}, false);
})();
</script>
<!--end data table section-->
</div>
@endsection
Вот мой взгляд