latest update youtube replica
This commit is contained in:
1 parent
5253f89b63
commit
b38f1a93bb
9 files changed
+1699
-295
No files matched your search
@@ -158,7 +158,7 @@ class VideoController extends Controller
|
||||
|
||||
// Send email notification
|
||||
try {
|
||||
Mail::to(Auth::user()->email)->send(new VideoUploaded($video));
|
||||
Mail::to(Auth::user()->email)->send(new VideoUploaded($video, Auth::user()->name));
|
||||
} catch (\Exception $e) {
|
||||
// Log the error but don't fail the upload
|
||||
\Log::error('Email notification failed: ' . $e->getMessage());
|
||||
@@ -199,13 +199,39 @@ class VideoController extends Controller
|
||||
return view('videos.show', compact('video'));
|
||||
}
|
||||
|
||||
public function edit(Video $video)
|
||||
public function edit(Video $video, Request $request)
|
||||
{
|
||||
return view('videos.edit', compact('video'));
|
||||
// Check if user owns the video
|
||||
if (Auth::id() !== $video->user_id) {
|
||||
abort(403, 'You do not have permission to edit this video.');
|
||||
}
|
||||
|
||||
// If not AJAX request, redirect to show page with edit parameter
|
||||
if (!$request->expectsJson() && !$request->ajax()) {
|
||||
return redirect()->route('videos.show', $video->id)->with('openEditModal', true);
|
||||
}
|
||||
|
||||
// For AJAX request, return JSON
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'video' => [
|
||||
'id' => $video->id,
|
||||
'title' => $video->title,
|
||||
'description' => $video->description,
|
||||
'thumbnail' => $video->thumbnail,
|
||||
'thumbnail_url' => $video->thumbnail ? asset('storage/thumbnails/' . $video->thumbnail) : null,
|
||||
'visibility' => $video->visibility ?? 'public',
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, Video $video)
|
||||
{
|
||||
// Check if user owns the video
|
||||
if (Auth::id() !== $video->user_id) {
|
||||
abort(403, 'You do not have permission to edit this video.');
|
||||
}
|
||||
|
||||
$request->validate([
|
||||
'title' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
@@ -231,6 +257,20 @@ class VideoController extends Controller
|
||||
|
||||
$video->update($data);
|
||||
|
||||
// Return JSON for AJAX requests
|
||||
if ($request->expectsJson() || $request->ajax()) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Video updated successfully!',
|
||||
'video' => [
|
||||
'id' => $video->id,
|
||||
'title' => $video->title,
|
||||
'description' => $video->description,
|
||||
'visibility' => $video->visibility,
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
return redirect()->route('videos.show', $video)->with('success', 'Video updated!');
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user