Home > Net >  ErrorException Undefined variable $transaksi
ErrorException Undefined variable $transaksi

Time:09-22

I was doing good other page, but for this have problem and I was tried and still not find.

ImportTransaksi_Controller

use Illuminate\Http\Request;

use App\Transaksi;

use Session;

use App\Imports\TransaksiImport;
use App\Exports\TransaksiExport;
use Maatwebsite\Excel\Facades\Excel;
use App\Http\Controllers\Controller;

class ImportTransaksi_Controller extends Controller
{
    //
    public function index()
    {
        $dso = Transaksi::all();
       
        return view('import.transaksi.index',['transaksi'=>$transaksi]);

and this is my index.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>Import Excel Ke Database Dengan Laravel</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>

    <div class="container">
        <center>
            <h2>Import Excel Ke Database Dengan Laravel</h2>
            <h3><a target="_blank" href="https://www.malasngoding.com/">www.malasngoding.com</a></h3>
        </center>

        {{-- notifikasi form validasi --}}
        @if ($errors->has('file'))
        <span class="invalid-feedback" role="alert">
            <strong>{{ $errors->first('file') }}</strong>
        </span>
        @endif

{{-- notifikasi sukses --}}
        @if ($sukses = Session::get('sukses'))
        <div class="alert alert-success alert-block">
            <button type="button" class="close" data-dismiss="alert">×</button> 
            <strong>{{ $sukses }}</strong>
        </div>
        @endif

        <button type="button" class="btn btn-primary mr-5" data-toggle="modal" data-target="#importExcel">
                IMPORT EXCEL
        </button>

I was tried to find where is the problem and see other page, everything is okay. I'm used laravel 8.6 and my database is mysql

CodePudding user response:

You have to use like below variable transaksi

$transaksi = Transaksi::all();
   
return view('import.transaksi.index',compact('transaksi'));

CodePudding user response:

On the return view() line, You have to change the variable from $transaksi to $dso, because there is no $transaksi variable

CodePudding user response:

You are assigning the wrong variable when sending it to the blade

public function index()
{
        $dso = Transaksi::all();
       
        return view('import.transaksi.index',['transaksi'=>$transaksi]);
}

Here the $transaksi is not assigned,

Instead you can declare variable as $transaksi like below

public function index()
{
     $transaksi = Transaksi::all();

     return view('import.transaksi.index',['transaksi'=>$transaksi]);
}
  • Related