Files
Test-Laravel-Eloquent-Basics/app/Http/Controllers/ProjectController.php
T

42 lines
1.0 KiB
PHP
Raw Normal View History

2021-11-16 09:49:29 +02:00
<?php
namespace App\Http\Controllers;
use App\Models\Project;
use Illuminate\Http\Request;
class ProjectController extends Controller
{
public function store(Request $request)
{
// TASK: Currently this statement fails. Fix the underlying issue.
Project::create([
'name' => $request->name
]);
return redirect('/')->with('success', 'Project created');
}
2021-11-16 09:58:36 +02:00
public function mass_update(Request $request)
{
// TASK: Transform this SQL query into Eloquent
// update projects
// set name = $request->new_name
// where name = $request->old_name
// Insert Eloquent statement below
return redirect('/')->with('success', 'Projects updated');
}
2021-11-16 10:45:45 +02:00
public function destroy($projectId)
{
Project::destroy($projectId);
// TASK: change this Eloquent statement to include the soft-deletes records
$projects = Project::all();
return view('projects.index', compact('projects'));
}
2021-11-16 09:49:29 +02:00
}