dimanche 20 août 2023

Undefined variable $artikels in foreach laravel

I have a problem with my laravel project where i can't show my data in the table. It keeps giving me undefined veriable $artikels in my writer.blade.php

So this is my controller

namespace App\Http\Controllers;

use App\Models\Artikel;
use Illuminate\Http\Request;

class ArtikelController extends Controller
{
    public function index()
    {
        $artikels = Artikel::all(); // Replace 'Artikel' with your actual model name

        return view('writer', compact('artikels'));
    }
}

this is my view in writer.blade.php

<table class="table table-bordered">
        <tr>
            <th>Image</th>
            <th>Judul</th>
            <th>Kategori</th>
            <th>Tag</th>
        </tr>
        @foreach ($artikels as $item)
        <tr>
            <td><img src="/gambar_artikel/" width="100px"></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        @endforeach
    </table>

and this is my route

Route::view('/', 'dashboard')->name('dashboard');
Route::view('/AboutMe', 'aboutme')->name('AboutMe');
Route::view('/Writer', 'writer')->name('writer');


Auth::routes();

Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');

Route::resource('/artikel', \App\Http\Controllers\ArtikelController::class);

how do i fix this problem? Thank you :)

I tried finding a lot of tutorials but it didn't fix my problem



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire