拨开荷叶行,寻梦已然成。仙女莲花里,翩翩白鹭情。
IMG-LOGO
主页 文章列表 未定义变量:tabelstok.blade.php上的键

未定义变量:tabelstok.blade.php上的键

白鹭 - 2022-03-17 2133 0 0

在我遇到这个问题之前,我尝试将数据库从 laravel 连接到 phpmyadmin,我认为它已经解决了我不知道它是否解决了或者还没有导致错误在它说“SQLSTATE [HY000] [1045] 访问之前说不同”拒绝用户'homestead'@'localhost'(使用密码:YES)”类似的东西,在我更改了一些代码之后,我又遇到了另一个问题。

我收到一条错误讯息,例如Undefined Variable: Key from this file name tabelstok.blade.php

来自tabelstok.blade.php 的代码

<!DOCTYPE html>
<html>
<head>
    <title>Tabelstok</title>
    <h1> Tabel Stok Master </h1>
</head>
<body>
    <table width="80%" border="1">
        <th> No </th>
        <th> Kode Barang </th>
        <th> Nama Barang </th>
        <th> Harga Barang Terakhir </th>
        <th> Id Satuan </th>

        <?php
        foreach ($ds as $key) {

        }
        ?>

        <tr>
        <td> {{$key->no}} </td>
        <td> {{$key->kode}} </td>
        <td> {{$key->nama}} </td>
        <td> {{$key->hbt}} </td>
        <td> {{$key->ids}} </td>
        </tr>
        
    </table>
</body>
</html>

这是我的控制器代码:

<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request; 

class regbcontroller extends BaseController     
{
    //class terdiri dari :
    //1. fungsi/method   atribut/data/variabel
public function fungsimenuregb(){
    return view ('regb.viewcontroller');
    }

public function fungsimenuregb2(){
    return view ('regb.viewcontroller2');
    }

public function fungsimenuparam(Request $r){
    $nil1=$r->nilai1;
    $nil2=$r->nilai2;

        return view ('regb.viewparam')
        ->with('nilaa1', $nil1)
        ->with('nilaa2', $nil2)
        ;
    }

    public function fungsitabelstok(Request $r){
        $ds=DB::table('tbbarang')
                 ->get();

        return view ('regb.tabelstok')
                 ->with('ds',$ds);

    }

public function simpantambahstok(Request $r){
    //proses simpan
    $simpan=array
    (
            'kode' => $r -> kd,
            'nama' => $r -> nama,
            'hbt' => $r -> hbt,
            'idsatuan' => $r -> ids
    );

    DB::table ('tbbarang') ->insertgetID($simpan);

    return redirect('tabelstok')
        -> with('pesan', 'profile updateSuccess');
}

}

这是我的路线代码:

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/


//UNTUK MEMANGGIL WELCOME
Route::get('/', function () {
    return view('welcome');
});



//UNTUK MENERIMA REQUEST MENUSATU
Route::get('/menusatu', function () {
    return view('regb.halamansatu');
});

Route::get('/menudua', function () {
    return view('regb.halamandua');
});

    
Route::get('/menukontroller','regbcontroller@fungsimenuregb');

Route::get('/menukontroller2','regbcontroller@fungsimenuregb2');

Route::get('/menu/{nilai1}/{nilai2}','regbcontroller@fungsimenuparam');

Route::get('/tabelstok','regbcontroller@fungsitabelstok');

Route::get('/tambahstok','regbcontroller@formtambahstok');

Route::get('/editstok', 'regbcontroller@formeditstok');

Route::post('/simpantambahstok', 'regbcontroller@simpantambahstok');

Route::post('/simpaneditstok', 'regbcontroller@simpaneditstok');

我不明白。请帮忙

uj5u.com热心网友回复:

好吧,我刚刚找到@lagbox的解决,我尝试对整个放<tr></tr>内环路他说的那样,它的作品。非常感谢 :D

uj5u.com热心网友回复:

您不在 foreach 回圈中。你的$key变量不在回圈中;)

标签:

0 评论

发表评论

您的电子邮件地址不会被公开。 必填的字段已做标记 *