when i tried to share my code preview blocked them how can i paste them like others?
Aug 18, 2025
5
Level 1
I cant see my images
SOLVED It turns out my model's fillable was 'image' not 'image_path' SOLVED
I was getting from chrome 403 error but now it got changed when i moved my project inside wamp64/www hence now i get 404 not found error. I have public/storage/news folder and able to see images both of the folders (public and storage) but i cant display name beside of it default placeholder appears.
Controller
<?php
namespace App\Http\Controllers;
use App\Models\News;
use App\Models\Club;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
class NewsController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//$news = News::all();
$news = News::latest()->get();
return view('news.index', compact('news'));
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$clubs = Club::all();
return view('news.create', compact('clubs'));
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$validated = $request->validate([
'title' => 'required|string|max:255',
'description' => 'required|string',
'image' => 'nullable|image|max:2048',
'club_id' => 'required|exists:clubs,id',
]);
$imagePath = null;
if ($request->hasFile('image')) {
$imagePath = $request->file('image')->store('news', 'public');
}
News::create([
'title' => $validated['title'],
'description' => $validated['description'],
'image_path' => $imagePath,
'club_id' => $validated['club_id'],
]);
return redirect()->route('news.index')->with('success', 'Haber oluşturuldu');
}
/**
* Display the specified resource.
*/
public function show(News $news)
{
$clubs = Club::all();
return view('news.show', compact('news'));
}
/**
* Show the form for editing the specified resource.
*/
public function edit(News $news)
{
$clubs = Club::all();
return view('news.edit', compact('news', 'clubs'));
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, News $news)
{
$validated = $request->validate([
'title' => 'required|string|max:255',
'description' => 'required|string',
'image' => 'nullable|image|max:2048',
'club_id' => 'required|exists:clubs,id',
]);
$imagePath = $news->image_path;
if ($request->hasFile('image')) {
if ($imagePath) {
Storage::disk('public')->delete($imagePath);
}
$imagePath = $request->file('image')->store('news', 'public');
}
$news->update([
'title' => $validated['title'],
'description' => $validated['description'],
'image_path' => $imagePath,
'club_id' => $validated['club_id'],
]);
return redirect()->route('news.index')->with('success', 'Haber güncellendi');
}
/**
* Remove the specified resource from storage.
*/
public function destroy(News $news)
{
if ($news->image_path) {
Storage::disk('public')->delete($news->image_path);
}
$news->delete();
return redirect()->route('news.index')->with('success', 'Haber silindi');
}
}
news/index.blade.php
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>@yield('title', 'Laravel App')</title>
<!-- Tailwind CSS CDN -->
@vite('resources/css/app.css')
<!-- Alpine.js for interactions -->
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js"></script>
@stack('styles')
</head>
<body class="bg-gray-50 min-h-screen">
<!-- Navbar -->
@include('layouts.public.navigation')
<!-- Flash Messages -->
@include('layouts.public.flash_message')
<div class="container mx-auto px-4 py-8 max-w-7xl">
<h2 class="text-3xl font-bold text-gray-800 mb-8 uppercase">haberler</h2>
<div class="mb-6">
<a href="{{ route('news.create') }}"
class="inline-block bg-blue-600 hover:bg-blue-700 text-white font-semibold py-2 px-4 rounded transition duration-200 uppercase">
HABER OLUŞTUR
</a>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
@foreach ($news as $i)
<div class="bg-white rounded-lg shadow-md overflow-hidden flex flex-col h-full">
@if ($i->image_path)
<img class="w-full h-48 object-cover" src="{{ asset('storage/' . $i->image_path) }}"
alt="{{ $i->title }}">
@else
<img class="w-full h-48 object-cover" src="https://via.placeholder.com/400x192"
alt="Placeholder">
@endif
<div class="p-6 flex-grow">
<h5 class="text-xl font-semibold text-gray-800 mb-3 line-clamp-1">{{ $i->title }}</h5>
<p class="text-gray-600 leading-relaxed line-clamp-3">{{ $i->description }}</p>
</div>
<div class="px-6 py-4 bg-gray-50 border-t border-gray-200 flex justify-between items-center">
<a href="{{ route('news.edit', $i->id) }}"
class="bg-green-600 hover:bg-green-700 text-white font-medium py-2 px-3 rounded text-sm transition duration-200 uppercase">
DÜZENLE
</a>
<form action="{{ route('news.destroy', $i->id) }}" method="POST" class="inline">
@csrf
@method('DELETE')
<button type="submit" onclick="return confirm('Silmek istediğine emin misin?')"
class="bg-red-600 hover:bg-red-700 text-white font-medium py-2 px-3 rounded text-sm transition duration-200 uppercase">
SİL
</button>
</form>
</div>
</div>
@endforeach
</div>
</div>
<!-- Footer -->
@include('layouts.public.footer')
@stack('scripts')
</body>
</html>
Please or to participate in this conversation.