97 lines
2.4 KiB
PHP
97 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Skill;
|
|
use Illuminate\Http\Request;
|
|
|
|
class SkillController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
$skills = Skill::latest()->get();
|
|
return view('skills.index', compact('skills'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
return view('skills.create');
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$validated = $request->validate([
|
|
'title' => 'required|string|max:255',
|
|
'description' => 'nullable|string',
|
|
'rating' => 'required|integer|min:1|max:10',
|
|
'image' => 'nullable|image|max:2048',
|
|
]);
|
|
|
|
$skill = Skill::create($validated);
|
|
|
|
if ($request->hasFile('image')) {
|
|
$skill->addMediaFromRequest('image')->toMediaCollection('image', 'public');
|
|
}
|
|
|
|
return redirect()->route('skills.index')->with('success', 'Vaardigheid toegevoegd.');
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(Skill $skill)
|
|
{
|
|
return view('skills.show', compact('skill'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit(Skill $skill)
|
|
{
|
|
return view('skills.edit', compact('skill'));
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, Skill $skill)
|
|
{
|
|
$validated = $request->validate([
|
|
'title' => 'required|string|max:255',
|
|
'description' => 'nullable|string',
|
|
'rating' => 'required|integer|min:1|max:10',
|
|
'image' => 'nullable|image|max:2048',
|
|
]);
|
|
|
|
$skill->update($validated);
|
|
|
|
if ($request->hasFile('image')) {
|
|
$skill->clearMediaCollection('image');
|
|
$skill->addMediaFromRequest('image')->toMediaCollection('image', 'public');
|
|
}
|
|
|
|
return redirect()->route('skills.index')->with('success', 'Vaardigheid bijgewerkt.');
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(Skill $skill)
|
|
{
|
|
$skill->clearMediaCollection('image');
|
|
$skill->delete();
|
|
|
|
return redirect()->route('skills.index')->with('success', 'Vaardigheid verwijderd.');
|
|
}
|
|
}
|