dynamic-banner-image-in-services

aplus#28
Mahesh Sharma 2 years ago
parent f4ed183a9a
commit d250c19200
  1. 25
      app/Http/Controllers/Admin/ServiceController.php
  2. 32
      database/migrations/2022_12_15_060949_add_banner_image_to_services_table.php
  3. BIN
      public/images/service/2022/12/15/f409d58f5e522b54f1cee39159c31b8d.png
  4. 6
      resources/views/admin/service/create.blade.php
  5. 14
      resources/views/admin/service/edit.blade.php
  6. 4
      resources/views/admin/visa_service_section/create.blade.php
  7. 4
      resources/views/admin/visa_service_section/edit.blade.php

@ -103,6 +103,15 @@ class ServiceController extends Controller
$out_put_path = User::save_image(\request('image'),$extension,$count,$image_folder_type); $out_put_path = User::save_image(\request('image'),$extension,$count,$image_folder_type);
is_array($out_put_path) ? $service->image = $out_put_path[0] : $service->image = $out_put_path; is_array($out_put_path) ? $service->image = $out_put_path[0] : $service->image = $out_put_path;
} }
if($request->hasFile('banner_image')){
$extension = \request()->file('banner_image')->getClientOriginalExtension();
$image_folder_type = array_search('service',config('custom.image_folders')); //for image saved in folder
$count = rand(100,999);
$out_put_path = User::save_image(\request('banner_image'),$extension,$count,$image_folder_type);
is_array($out_put_path) ? $service->banner_image = $out_put_path[0] : $service->banner_image = $out_put_path;
}
if($service->save()){ if($service->save()){
@ -215,6 +224,22 @@ class ServiceController extends Controller
is_array($out_put_path) ? $service->image = $out_put_path[0] : $service->image = $out_put_path; is_array($out_put_path) ? $service->image = $out_put_path[0] : $service->image = $out_put_path;
}
if($request->hasFile('banner_image')){
$extension = \request()->file('banner_image')->getClientOriginalExtension();
$image_folder_type = array_search('service',config('custom.image_folders')); //for image saved in folder
$count = rand(100,999);
$out_put_path = User::save_image(\request('banner_image'),$extension,$count,$image_folder_type);
if (is_file(public_path().'/'.$service->banner_image) && file_exists(public_path().'/'.$service->banner_image)){
unlink(public_path().'/'.$service->banner_image);
}
is_array($out_put_path) ? $service->banner_image = $out_put_path[0] : $service->banner_image = $out_put_path;
} }
if($service->update()){ if($service->update()){
Session::flash('success','Service has been successfully updated!'); Session::flash('success','Service has been successfully updated!');

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('services', function (Blueprint $table) {
$table->string('banner_image')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('services', function (Blueprint $table) {
//
});
}
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 510 KiB

@ -122,6 +122,12 @@
<input type="file" class="form-control" id="image" name="image" required> <input type="file" class="form-control" id="image" name="image" required>
</div> </div>
</div> </div>
<div class="col-md-4">
<div class="form-group">
<label for="banner_image">Banner Image <span style="color: red">*</span></label>
<input type="file" class="form-control" id="banner_image" name="banner_image">
</div>
</div>
<div class="col-md-4"> <div class="col-md-4">
<div class="form-group"> <div class="form-group">
<label>Status <span style="color: red">*</span> </label> <label>Status <span style="color: red">*</span> </label>

@ -91,6 +91,20 @@
@endif @endif
</div> </div>
</div> </div>
<div class="col-md-4">
<div class="form-group">
<label for="banner_image"> Banner Image <span style="color: red">*</span></label>
<input type="file" class="form-control" id="banner_image" name="banner_image">
@if($service->banner_image != null)
<span>
<a href="{{url($service->banner_image)}}" target="_blank">
<img src="{{url($service->banner_image)}}" alt="" style="width: 100px;">
</a>
</span>
@endif
</div>
</div>

@ -37,7 +37,7 @@
<div class="col-md-4"> <div class="col-md-4">
<div class="form-group"> <div class="form-group">
<label for="left_title">Left Title<span style="color: red">*</span></label> <label for="left_title">Left Title<span style="color: red">*</span></label>
<input type="text" class="form-control" id="left_title" name="left_title" required> <input type="text" class="form-control" id="left_title" name="left_title">
</div> </div>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
@ -56,7 +56,7 @@
<div class="col-md-4"> <div class="col-md-4">
<div class="form-group"> <div class="form-group">
<label for="right_title">Right Title<span style="color: red">*</span></label> <label for="right_title">Right Title<span style="color: red">*</span></label>
<input type="text" class="form-control" id="right_title" name="right_title" required> <input type="text" class="form-control" id="right_title" name="right_title">
</div> </div>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">

@ -37,7 +37,7 @@
<div class="col-md-4"> <div class="col-md-4">
<div class="form-group"> <div class="form-group">
<label for="left_title">Left Title<span style="color: red">*</span></label> <label for="left_title">Left Title<span style="color: red">*</span></label>
<input type="text" class="form-control" id="left_title" name="left_title" value = "{{$service_section->left_title}}" required> <input type="text" class="form-control" id="left_title" name="left_title" value = "{{$service_section->left_title}}">
</div> </div>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
@ -56,7 +56,7 @@
<div class="col-md-4"> <div class="col-md-4">
<div class="form-group"> <div class="form-group">
<label for="right_title">Right Title<span style="color: red">*</span></label> <label for="right_title">Right Title<span style="color: red">*</span></label>
<input type="text" class="form-control" id="right_title" name="right_title" value = "{{$service_section->right_title}}" required> <input type="text" class="form-control" id="right_title" name="right_title" value = "{{$service_section->right_title}}">
</div> </div>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">

Loading…
Cancel
Save