Cố gắng đọc tên thuộc tính'' trên mảng laravel

Xin chào,

Tôi đang sử dụng sự kiện nhấp vào nút [thành phần. lưỡi]

@foreach[$cards as $card]

@endforeach

Kết quả trong


        

Phương thức được gọi

public function gotClicked[$card]
{

    $bid = session['bid'];
    
    if[$bid == $card]{
        dd['HURRAY!!!'];
    }
}

Khi tôi nhấp vào một trong các nút, lỗi sau sẽ xuất hiện

Cố đọc thuộc tính “id” trên mảng

Nhưng khi tôi đặt một dd[] trong phương thức như vậy

public function gotClicked[$card]
{
    dd[$card];
    $bid = session['bid'];
    
    if[$bid == $card]{
        dd['HURRAY!!!'];
    }
}

Tôi nhận được giá trị của $card

Tôi thực sự không hiểu và không hiểu tại sao nó không hoạt động
Khi tôi sử dụng {{ $card['id'] }} nó hoàn toàn không hoạt động. Bởi vì ID không được in

cám ơn

Thay vào đó, bạn nên sử dụng

Schema::create['users', function [Blueprint $table] {
$table->id[];
$table->string['name'];
$table->string['email']->unique[];
$table->timestamp['email_verified_at']->nullable[];
$table->string['password'];
$table->rememberToken[];
$table->unsignedBigInteger['division_id']->nullable[];
$table->timestamps[];
}];

4 để lấy tên của bộ phận, nhưng nếu bạn sử dụng trực tiếp tên thuộc tính
Schema::create['users', function [Blueprint $table] {
$table->id[];
$table->string['name'];
$table->string['email']->unique[];
$table->timestamp['email_verified_at']->nullable[];
$table->string['password'];
$table->rememberToken[];
$table->unsignedBigInteger['division_id']->nullable[];
$table->timestamps[];
}];

5 thì nó sẽ đưa ra một lỗi khác, vì mô hình người dùng mặc định của Laravel không nhập Mô hình Eloquent

1
Schema::create['users', function [Blueprint $table] {
$table->id[];
$table->string['name'];
$table->string['email']->unique[];
$table->timestamp['email_verified_at']->nullable[];
$table->string['password'];
$table->rememberToken[];
$table->unsignedBigInteger['division_id']->nullable[];
$table->timestamps[];
}];

1

Để giải quyết vấn đề này, chúng tôi cần thêm dòng này vào tệp mô hình Người dùng của bạn

Schema::create['users', function [Blueprint $table] {
$table->id[];
$table->string['name'];
$table->string['email']->unique[];
$table->timestamp['email_verified_at']->nullable[];
$table->string['password'];
$table->rememberToken[];
$table->unsignedBigInteger['division_id']->nullable[];
$table->timestamps[];
}];

2

Chủ Đề