1
0
mirror of https://github.com/cp6/my-idlers.git synced 2024-11-16 23:42:32 +01:00

Added os select component

Added os select component
This commit is contained in:
cp6 2022-03-06 00:54:24 +11:00
parent a7d0e07723
commit a9adf342c0
3 changed files with 35 additions and 0 deletions

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use App\Models\OS; use App\Models\OS;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
class OsController extends Controller class OsController extends Controller
{ {
@ -28,6 +29,8 @@ class OsController extends Controller
'name' => $request->os_name 'name' => $request->os_name
]); ]);
Cache::forget('all_os');
return redirect()->route('os.index') return redirect()->route('os.index')
->with('success', 'OS Created Successfully.'); ->with('success', 'OS Created Successfully.');
} }
@ -38,6 +41,8 @@ class OsController extends Controller
$items->delete(); $items->delete();
Cache::forget('all_os');
return redirect()->route('os.index') return redirect()->route('os.index')
->with('success', 'OS was deleted Successfully.'); ->with('success', 'OS was deleted Successfully.');
} }

View File

@ -0,0 +1,20 @@
<?php
namespace App\View\Components;
use App\Models\OS;
use Illuminate\Support\Facades\Cache;
use Illuminate\View\Component;
class OsSelect extends Component
{
public function render()
{
$all_os = Cache::rememberForever('all_os', function () {
return OS::all();
});
return view('components.os-select', [
'os' => $all_os
]);
}
}

View File

@ -0,0 +1,10 @@
<div class="input-group">
<div class="input-group-prepend"><span class="input-group-text">{{ $title ??'OS'}}</span></div>
<select class="form-control" name="{{$name ?? 'os_id'}}">
@foreach ($os as $o)
<option value="{{ $o['id'] }}" {{(isset($current) && (string)$current === (string)$o['id'])? 'selected' : ''}}>
{{ $o['name'] }}
</option>
@endforeach
</select>
</div>