Laravel 中的空属性

问题描述 投票:0回答:1

我正在尝试编辑数据库输出,但是当我使用

dd($customerlist);
时,我得到空属性。

web.php(路线)

Route::get('/customer/{customer}/edit', 'App\Http\Controllers\CustomerListController@edit')->name('customer.edit');

CustomerListController.php(控制器)

    public function edit(Customerlist $customerlist)
    {
        dd($customerlist);
    }
        

customerlist.blade.php

        <tbody class="divide-y divide-gray-200">
            @foreach ($customers as $customer)
                <tr>
                    <td class="px-6 py-4 whitespace-nowrap">{{ $customer->Naam }}</td> 
                    <td class="px-6 py-4 whitespace-nowrap">{{ $customer['Bank_Account_Number'] }}</td> 
                    <td class="px-6 py-4 whitespace-nowrap">{{ $customer['Social_Security_Number'] }}</td> 
                    <td class="px-6 py-4 whitespace-nowrap">
                        <a href="{{ route('customer.edit', ['customer' => $customer]) }}" class="text-blue-500 hover:underline">Edit</a>
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap">
                        <form action="{{ route('customer.destroy', $customer['id']) }}" method="POST">
                            @csrf
                            @method('DELETE')
                            <button type="submit" class="text-red-500 hover:text-red-700">Delete</button>
                        </form>
                    </td>
                </tr>
            @endforeach
        </tbody>
    </table>

CustomerList.php(模型)

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class CustomerList extends Model
{
    use HasFactory;

    protected $table = 'customerlists';
    protected $fillable = ['Naam', 'Bank_Account_Number', 'Social_Security_Number'];
}

我的 web.php、CustomerListController 和 Blade 文件中有更多代码,我只是展示我认为必要的内容,我的控制器中还有其他 100% 有效的 CRUD 操作。这些是创建和删除。我的数据库也在我的网站上输出。

我希望有人可以帮助我,如果您需要更多代码来帮助,请告诉我!

php laravel laravel-blade crud
1个回答
0
投票

操作中的变量必须与路由中设置的变量匹配:

public function edit(Customerlist $customer)
© www.soinside.com 2019 - 2024. All rights reserved.