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

55 lines
1.4 KiB
PHP
Raw Normal View History

2021-11-16 09:49:29 +02:00
<?php
namespace App\Http\Controllers;
use App\Models\Project;
2021-11-16 11:02:41 +02:00
use App\Models\Stat;
2021-11-16 09:49:29 +02:00
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 11:02:41 +02:00
public function store_with_stats(Request $request)
{
// TASK: on creating a new project, create an Observer event to run SQL
// update stats set projects_count = projects_count + 1
$project = new Project();
$project->name = $request->name;
$project->save();
return redirect('/')->with('success', 'Project created');
}
2021-11-16 09:49:29 +02:00
}