Изображение не отображается.
Это мой код:
public function index()
{
//
$categories = Category::with('children')->get();
return view('dashboard.categories.index',compact('categories'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
$categories = Category::all();
return view('dashboard.categories.create',compact('categories'));
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
$category = new Category();
$category->title = $request->title;
$category->content = $request->content;
$filename = sprintf('thumbnail_%s.jpg',random_int(1, 1000));
if ($request->hasFile('thumbnail'))
$filename = $request->file('thumbnail')->storeAs('images',$filename,'public');
else
$filename = null;
$category->thumbnail = $filename;
$category->parent_id = $request->parent_id;
$save = $category->save();
if ($save) {
return redirect()->route('categories.index');
}
}
Это контроллер, и индексная функция используется для просмотра списка. Create используется для формы, функция store используется для сохранения значений
@extends('dashboard.layout')
@section('content')
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h2 class="h2">categories Section</h2>
<div class="btn-toolbar mb-2 mb-md-0">
<div class="btn-group mr-2">
<a href="{{route('categories.create')}}" type="button" class="btn btn-sm btn-outline-secondary">Add New category</a>
</div>
</div>
</div>
@if(!$categories->isEmpty())
<div class="table-responsive">
<table class="table table-striped table-sm">
<thead>
<tr>
<th>#</th>
<th>Title</th>
<th>Content</th>
<th>Thumbnail</th>
<th>Created At</th>
<th>Updated At</th>
<th>Children</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach($categories as $category)
<tr>
<td>{{$category->id}}</td>
<td>{{$category->title}}</td>
<td>{{$category->content}}</td>
<td><img src="{{asset($category->thumbnail)}}" width="100" height="100" /></td>
<td>{{$category->created_at}}</td>
<td>{{$category->updated_at}}</td>
<td>
@if(!$category->children->isEmpty())
@foreach($category->children as $children)
{{$children->title}}
@endforeach
@else
{{'Parent Category'}}
@endif
</td>
<td>
<div class="btn btn-group" category="group" aria-label="Basic example">
<a category="button" href="{{route('categories.edit',$category->id)}}" class="btn btn-link">Edit</a>
| <form method="post" action="{{route('categories.destroy',$category->id)}}">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-link">Delete</button>
</form>
<a category="button" href="{{route('categories.show',$category->id)}}" class="btn btn-link">Show</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@else
<p class="alert alert-info">No categories Found...</p>
@endif
@endsection
Это представление
Я использовал этот код, и для создания и просмотра функционала создания он работает успешно. Функция view () также работает, но изображение не отображается.
Кто-нибудь подскажет, где ошибка пути и как ее решить?