Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Undefined variable $datas in laravel 9

enter image description here

Undefined variable, how can I ask for help

But I have declared $datas on the controller like this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Controller

class JenisImunisasiController extends Controller
{
public function index() {

      $jenis = JenisImunisasi::get();
      return view('admin.jenisimunisasi.index', ['jenis_imunisasis' => $jenis]);
    
    }

}

and the view like this

index.blade.php

  @foreach ($datas as $key => $data)
                    <tr>
                        <th>{{ $datas->firstItem() + $key}}</th>
                        <th>{{ $data->nama_imun}}</th>
                        <th>{{ $data->umur }}</th>
                        <th>
                        </th>
                    </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
        <div>
            Showing
            {{  $datas->firstItem() }}
            to
            {{  $datas->lastItem() }}
            of
            {{  $datas->total() }}
            Entries
        </div>
        <div class="fa-pull-right">
            {{ $datas->links() }}
        </div>
    </div>

>Solution :

Here check my code you need to pass key as datas instead of jenis_imunisasis in view function second parametere

class JenisImunisasiController extends Controller
{
    public function index()
    {

        $jenis = JenisImunisasi::get();
        return view('admin.jenisimunisasi.index', ['datas' => $jenis]);
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading