-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComputerScienceResourceController.php
More file actions
95 lines (81 loc) · 2.9 KB
/
ComputerScienceResourceController.php
File metadata and controls
95 lines (81 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace App\Http\Controllers;
use App\Http\Requests\ComputerScienceResource\StoreResourceRequest;
use App\Models\ComputerScienceResource;
use App\Models\ResourceReview;
use Illuminate\Database\Console\DumpCommand;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Auth;
class ComputerScienceResourceController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
// Eager load topic tags and other tag types as needed
$resources = ComputerScienceResource::paginate(10);
return Inertia::render('Resources/Index', [
'resources' => $resources,
]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
return Inertia::render('Resources/Create');
}
/**
* Store a newly created resource in storage.
*/
public function store(StoreResourceRequest $request)
{
$validatedData = $request->validated();
Log::debug("Called store resource with data " . json_encode($request));
$resource = ComputerScienceResource::create([
'user_id' => Auth::id(),
'name' => $validatedData['name'],
'image_url' => $validatedData['image_url'],
'description' => $validatedData['description'],
'page_url' => $validatedData['page_url'],
'platforms' => $validatedData['platforms'],
'difficulty' => $validatedData['difficulty'],
'pricing' => $validatedData['pricing'],
]);
// Add topics as tags
$resource->topic_tags = $validatedData['topic_tags'];
// Add programming languages as tags (if provided)
if (isset($validatedData['programming_language_tags'])) {
$resource->programming_language_tags = $validatedData['programming_language_tags'];
}
// Add general tags (if provided)
if (isset($validatedData['general_tags'])) {
$resource->general_tags = $validatedData['general_tags'];
}
Log::debug("Created resource " . json_encode($resource));
return redirect(route('resources.show', ['computerScienceResource'=>$resource->id]))
->with('success', 'Created Resource Succesfully!');
}
/**
* Display the specified resource.
*/
public function show(ComputerScienceResource $computerScienceResource)
{
$reviews = $computerScienceResource->reviews()->orderByDesc('created_at')->get();
return Inertia::render('Resources/Show', [
'resource' => fn() => $computerScienceResource->load('user'),
'reviews' => fn () => $reviews,
]);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(ComputerScienceResource $computerScienceResource)
{
//
}
}