irankhosravi
3 months ago

Invalid argument supplied for foreach()

Posted 3 months ago by irankhosravi

I want to display checkbox with where('category_id')?

My table is:

public function up()
{
    Schema::create('computers', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->bigInteger('category_id')->unsigned();
        $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
        $table->string('name');
        $table->string('latin');
        $table->timestamps();
    });
}

<y blade

@foreach ($computers->where('category_id', 2)->first() as $computer)
    <input type="checkbox" id="{{ $computer->latin }}" name="[]">
    <label for="{{ $computer->latin }}">{{ $computer->name }}</label>
@endforeach

I see this error

ErrorException (E_ERROR) Invalid argument supplied for foreach() (View: C:\xampp\htdocs\new\shopping\resources\views\Home\computers.blade.php)

Please sign in or create an account to participate in this conversation.