Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions app/Http/Controllers/VideoController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Show;
use App\Models\Video;
use App\Models\Artist;

class VideoController extends Controller
{
public function showVideos($showId)
{
$show = Show::with('videos')->findOrFail($showId);
return view('shows.videos', compact('show'));
}

public function store(Request $request, $showId)
{
$request->validate([
'title' => 'required|max:255',
'video_url' => 'required|url|unique:videos,video_url',
]);

$show = Show::findOrFail($showId);

if ($show->representations->isEmpty()) {
return redirect()->back()->withErrors(['error' => 'pas de representation pour ce show']);
}

$video = new Video($request->all());
$video->show_id = $showId;
$video->save();

return redirect()->route('show.videos', $showId);
}
public function showArtistVideos($name)
{
$artist = Artist::where('name', $name)->firstOrFail();
$shows = $artist->shows()->with('videos')->get();

return view('artists.videos', compact('artist', 'shows'));
}
}
6 changes: 5 additions & 1 deletion app/Models/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ public function representations()
{
return $this->hasMany(Representation::class);
}

// relation video examen
public function videos()
{
return $this->hasMany(Video::class);
}
public function location()
{
return $this->belongsTo(Location::class);
Expand Down
18 changes: 18 additions & 0 deletions app/Models/Video.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Video extends Model
{
use HasFactory;

protected $fillable = ['title', 'video_url', 'show_id'];

public function show()
{
return $this->belongsTo(Show::class);
}
}
13 changes: 12 additions & 1 deletion app/Policies/AdminPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@

use App\Models\User;
use Illuminate\Auth\Access\Response;

use Illuminate\Auth\Access\HandlesAuthorization;
use Illuminate\Support\Facades\Log;
class AdminPolicy
{

public function admin(User $user)
{
return $user->isAdmin()
? Response::allow()
: Response::deny('Vous devez être administrateur pour ajouter une video');

Log::info('User is admin');
}

/**
* Determine whether the user can view any models.
*/
Expand Down
30 changes: 30 additions & 0 deletions database/migrations/2024_05_31_074314_create_videos_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('videos', function (Blueprint $table) {
$table->id();
$table->string('title', 255);
$table->string('video_url', 255)->unique();
$table->foreignId('show_id')->constrained()->onUpdate('cascade')->onDelete('restrict');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('videos');
}
};
2 changes: 2 additions & 0 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public function run(): void
ReviewSeeder::class,
TagSeeder::class,
ShowTagSeeder::class,
VideoSeeder::class,

]);
}
}
26 changes: 26 additions & 0 deletions database/seeders/VideoSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\Show;
use App\Models\Video;

class VideoSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
// ajout d'une video pour le show
$show = Show::first();

Video::create([
'title' => 'Tintin Video',
'video_url' => 'https://youtu.be/ERA14Xjjtlk',
'show_id' => $show->id,
]);
}
}
Binary file removed public/posters/dd.png
Binary file not shown.
18 changes: 18 additions & 0 deletions resources/views/artists/videos.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<x-app-layout>
<h1>Vidéos des spectacles de {{ $artist->name }}</h1>

@foreach ($shows as $show)
<h2>{{ $show->title }}</h2>
@if ($show->videos->isEmpty())
<p>Aucune vidéo pour ce spectacle.</p>
@else
@foreach ($show->videos as $video)
<div>
<h3>{{ $video->title }}</h3>
<video src="{{ $video->video_url }}" controls></video>
</div>
@endforeach
@endif
@endforeach
</x-app-layout>

28 changes: 26 additions & 2 deletions resources/views/show/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,37 @@ class="text-indigo-600 font-semibold text-sm dark:text-indigo-400 hover:text-ind
Retour</a>
</div>

<div>
<h1 class="text-2xl font-semibold text-gray-900 dark:text-gray-100">{{ $show->title }}</h1>
</div>
<div class="w-full flex">
<div class="w-56 mr-10 flex-shrink-0">
@if ($show->poster_url)
<img src="{{ asset('images/' . $show->poster_url) }}" alt="{{ $show->title }}"
class="object-cover w-full h-auto">
@endif
</div>
<h1>{{ $show->title }} - Videos</h1>

@if ($show->videos->isEmpty())
<p>Aucune vidéo pour ce spectacle.</p>
@else
@foreach ($show->videos as $video)
<div>
<h2>{{ $video->title }}</h2>
<video src="{{ $video->video_url }}" controls></video>
</div>
@endforeach
@endif
<!--j'ai utiliser lepolicy addTag -->
@can('addTag', App\Models\Tag::class)
<form action="{{ route('video.store', $show->id) }}" method="POST">
@csrf
<input type="text" name="title" placeholder="Title" required>
<input type="url" name="video_url" placeholder="Video URL" required>
<button type="submit">Add Video</button>
</form>
@endcan

<div class="flex flex-col w-full">
<h2 class="text-xl font-semibold text-gray-900 dark:text-gray-100">{{ $show->title }}</h2>
Expand Down Expand Up @@ -108,7 +132,8 @@ class="text-indigo-600 font-semibold text-sm dark:text-indigo-400 hover:text-ind
Réserver
</a>
@else
<span class="text-red-500 text-sm font-semibold">Non réservable</span>
<span class="text-red-500 text-sm font-semibold">Non
réservable</span>
@endif
</td>
</tr>
Expand All @@ -128,4 +153,3 @@ class="text-indigo-600 font-semibold text-sm dark:text-indigo-400 hover:text-ind
</div>
</x-app-layout>


25 changes: 25 additions & 0 deletions resources/views/show/videos.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<x-app-layout>
<!-- partie de l'examen pur -->
<h1>{{ $show->title }} - Videos</h1>

@if ($show->videos->isEmpty())
<p>Aucune vidéo pour ce spectacle.</p>
@else
@foreach ($show->videos as $video)
<div>
<h2>{{ $video->title }}</h2>
<video src="{{ $video->video_url }}" controls></video>
</div>
@endforeach
@endif

@can('admin')
<form action="{{ route('video.store', $show->id) }}" method="POST">
@csrf
<input type="text" name="title" placeholder="Title" required>
<input type="url" name="video_url" placeholder="Video URL" required>
<button type="submit">Add Video</button>
</form>
@endcan
</x-app-layout>

11 changes: 11 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@
use App\Http\Controllers\ScheduleController;
use App\Http\Controllers\Admin\AdminRepresentationController;
use App\Http\Controllers\ContactFormController;
use App\Http\Controllers\VideoController;
/*
|--------------------------------------------------------------------------
| Routes Video - Examen
|--------------------------------------------------------------------------
*/
Route::get('show/{showId}/videos', [VideoController::class, 'showVideos'])->name('show.videos');
Route::post('show/{showId}/videos', [VideoController::class, 'store'])->middleware('can:admin')->name('video.store');

Route::get('artist/{name}/videos', [VideoController::class, 'showArtistVideos'])->name('artist.videos');

/*
|--------------------------------------------------------------------------
| Routes home
Expand Down