25 lines
556 B
PHP
25 lines
556 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Video;
|
|
use App\Models\VideoView;
|
|
use Illuminate\Http\Request;
|
|
|
|
class VideoViewController extends Controller
|
|
{
|
|
public function store(Video $video) {
|
|
$user = auth()->user();
|
|
|
|
//firstOrCreate só cria se não existir, se existir, atualiza o watched_at
|
|
VideoView::firstOrCreate([
|
|
'user_id' => $user->id,
|
|
'video_id' => $video->id,
|
|
], [
|
|
'watched_at' => now(),
|
|
]);
|
|
|
|
return response()->json(['watched' => true]);
|
|
}
|
|
}
|