Initial commit
This commit is contained in:
96
app/Http/Controllers/SkillController.php
Normal file
96
app/Http/Controllers/SkillController.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?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.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user