Skip to content

Commit

Permalink
#94 - Video support in header media
Browse files Browse the repository at this point in the history
  • Loading branch information
ttimot24 committed Nov 4, 2024
1 parent 5809802 commit f9142b0
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
4 changes: 4 additions & 0 deletions app/Controllers/HeaderImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public function store(Request $request)
$header_image = new HeaderImage($request->all());
$header_image->author()->associate($request->user());

if($request->hasFile($this->form_field_name)){
$header_image->type = explode('/',request()->{$this->form_field_name}->getMimeType())[0];
}

$this->uploadImage($header_image);

if ($header_image->save()) {
Expand Down
2 changes: 1 addition & 1 deletion app/Controllers/Trait/UploadsImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function uploadImage($model): bool {
File::ensureDirectoryExists($model->getImageDirectory());
$img = request()->{$this->form_field_name}->store($this->getStrippedDirectoryPath($model));
$model->attachImage($img);
if (extension_loaded('gd')) {
if (extension_loaded('gd') && starts_with(request()->{$this->form_field_name}->getMimeType(), 'image/')) {
File::ensureDirectoryExists($model->getImageDirectory() . '/thumbs');
\Intervention\Image\ImageManagerStatic::make(storage_path($img))->fit(300, 200)->save($model->getThumbnailDirectory(). DIRECTORY_SEPARATOR . $model->image);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Model/HeaderImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class HeaderImage extends Model {
* @var array
*/
protected $fillable = [
'title', 'link' ,'description', 'image', 'active',
'title', 'type' ,'link' ,'description', 'image', 'active',
];

}
20 changes: 18 additions & 2 deletions app/View/media/header_images.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,19 @@
<span class='fa fa-pencil' aria-hidden='true'
style=' font-size: 1.4em;z-index:15;top:3px;right:3px;margin-bottom:-15px;'></span>
</a>

@if($each->type === 'video')
<video controls width='100%' height='75%;' style="object-fit:cover;">
<source src="storage/images/header_images/{{ $each->image }}" >
Your browser does not support the video tag.
</video>
@else
<img src='storage/images/header_images/{{ $each->image }}' alt=''
class='card-img-top' width='100%' height='75%;' style="object-fit:cover;">
@endif

<div class="card-body text-black">
<h5 class="card-title">{{ $each->title }}</h5>
<h5 class="card-title">{{ $each->title }} <small> | {{$each->type}}</small></h5>
</div>
<ul class="list-group list-group-flush mb-3">
<a class='btn btn-danger btn-xs btn-block'
Expand Down Expand Up @@ -175,8 +184,15 @@ class='btn btn-primary'>{{ trans('actions.save') }}</button>
</div>
</div>
</div>
@if($each->type === 'video')
<video controls width='100%' height='75%;' style="object-fit:cover;">
<source src="storage/images/header_images/{{ $each->image }}" >
Your browser does not support the video tag.
</video>
@else
<img src='storage/images/header_images/{{ $each->image }}' alt=''
class='card-img-top' width='100%' height='75%;' style="object-fit:cover;">
@endif
<div class="card-body text-black">
<h5 class="card-title">{{ $each->title }}</h5>
</div>
Expand Down Expand Up @@ -289,7 +305,7 @@ class='btn btn-primary'>{{ trans('actions.save') }}</button>
@csrf
<div class='form-group'>
<label for='file'>Upload file:</label>
<input name='up_file' id='input-2' type='file' class='file' accept="image/*"
<input name='up_file' id='input-2' type='file' class='file' accept="image/*, video/*"
multiple='true' data-show-upload='false' data-show-caption='true' required>
</div>
<div class="mb-3">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function up()
Schema::create($this->table_name, function (Blueprint $table) {
$table->increments('id');
$table->string('title')->nullable();
$table->string('type')->nullable();
$table->string('link')->nullable();
$table->text('description')->nullable();
$table->string('image');
Expand Down
1 change: 1 addition & 0 deletions database/seeders/ContentSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function run()
DB::table('header_images')->insert([
'id' => 1,
'title' => 'default',
'type' => 'image',
'image' => 'abovethecity.jpg',
'author_id' => 1,
'active' => 1
Expand Down

0 comments on commit f9142b0

Please sign in to comment.