Skip to content

Instantly share code, notes, and snippets.

@nafiesl
Last active November 6, 2024 05:25
Show Gist options
  • Save nafiesl/fc851d38f9c8ee79e5e73facedb2ac03 to your computer and use it in GitHub Desktop.
Save nafiesl/fc851d38f9c8ee79e5e73facedb2ac03 to your computer and use it in GitHub Desktop.
Laravel Select Dropdown Example
<div class="form-group">
<label for="model_id" class="control-label">Model Unit</label>
<select name="model_id" id="model_id" class="form-control{{ $errors->has('model_id') ? ' is-invalid' : '' }}" required>
<option value="">-- Pilih Model --</option>
@foreach ($unitModels as $unitModel)
<option value="{{ $unitModel->id }}" {{ $unitModel->id == old('model_id', request('model_id')) ? 'selected' : '' }}>
{{ $unitModel->code }} - {{ $unitModel->name }}
</option>
@endforeach
</select>
{!! $errors->first('model_id', '<span class="invalid-feedback" role="alert">:message</span>') !!}
</div>
<?php
namespace App\Http\Controllers;
use App\UnitType;
use App\UnitModel;
class UnitTypeController extends Controller
{
public function edit(UnitType $unitType)
{
$unitModels = UnitModel::all();
return view('unit_types.edit', compact('unitType', 'unitModels'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment