I have categories table.
public function up()
{
Schema::create('categories', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->text('description');
$table->integer('parent_id')->default(0);
$table->timestamps();
});
}
And I have computers table.
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();
});
}
ComputerController.php
public function index ()
{
$computers = Computer::all();
$categories = Category::where('parent_id', '=', 4)->get();
return view('Home.computers', compact('categories', 'computers'));
}
computers.blade.php
<form action="{{ route('computers.store') }}" method="post">
{{ csrf_field() }}
<div class="form-group">
<select id="select" name="category_id" class="form-control">
@foreach($categories as $category)
<option data-description="{{ $category->description }}" value="{{ $category->id }}">{{ $category->name }}</option>
@endforeach
</select>
</div>
<div class="form-group">
<p id="description"></p>
</div>
<div class="form-group laptop_repair box">
<p></p>
@foreach ($computers->where('category_id', 2) as $computer)
<input type="checkbox" id="{{ $computer->latin }}">
<label for="{{ $computer->latin }}">{{ $computer->name }}</label>
@endforeach
</div>
<div class="form-group install_windows box">
<p></p>
@foreach ($computers->where('category_id', 3) as $computer)
<input type="checkbox" id="{{ $computer->latin }}">
<label for="{{ $computer->latin }}">{{ $computer->name }}</label>
@endforeach
</div>
<div class="form-group backup box">
<p></p>
@foreach ($computers->where('category_id', 4) as $computer)
<input type="checkbox" id="{{ $computer->latin }}">
<label for="{{ $computer->latin }}">{{ $computer->name }}</label>
@endforeach
</div>
<div class="form-group">
<button class="btn btn-primary">Save</button>
</div>
</form>
I tried show checkboxes when I click and select a option but it did not display.
And But I did the following but did not show.