Skip to main content

add and store multiple file by clicking add button and remove button


Store Function

public function store(Request $request) { $array_size = (sizeof($request->title)); if ($array_size > 0) { foreach ($request->file('image') as $i => $image) { if (!empty($image)) { $path = base_path() . '/public/gallery_upload'; $pimage = uniqid() . '_' . $image->getClientOriginalName(); if ($image->move($path, $pimage)) { $status = Featured::create([ 'img' => $pimage, 'date' => $request->featuredsdate[$i], 'title' => $request->title[$i], 'link' => $request->link[$i], 'news_id' => $request->news_id, ]); } } } } return $this->gallerycreate($request->news_id); }


Update Function


public function updatefeature(Request $request)
{

$fid = $request->fid;
$array_size = count($request->input('title'));
$title = $request->input('title');
$featureddate = $request->input('featureddate');
$link = $request->input('link');
$img = $request->file('image');

if ($array_size > 0) {
for ($i = 0; $i < $array_size; $i++) {
if (isset($fid[$i])) {
$featurestore = Featured::find($fid[$i]);
$featurestore->news_id = $request->input('news_id');
$featurestore->title = $title[$i];
$featurestore->link = $link[$i];
$path = base_path() . '/public/gallery_upload';
//for changing image
if ($img != null) {

if (array_key_exists($i, $img)) {

$singimg = $img[$i];

$pimage = uniqid() . '_' . $singimg->getClientOriginalName();
if ($singimg->move($path, $pimage)) {
$featurestore->img = $pimage;

}

}

}
//for changing image

$featurestore->date = $featureddate[$i];
$status = $featurestore->update();

} elseif (!isset($fid[$i]) && $title[$i] != null) {

foreach ($request->file('image') as $i => $image) {
if (!empty($image)) {
$path = base_path() . '/public/gallery_upload';
$pimage = uniqid() . '_' . $image->getClientOriginalName();
if ($image->move($path, $pimage)) {
$status = Featured::create([
'img' => $pimage,
'date' => $request->featuredsdate[$i],
'title' => $request->title[$i],
'link' => $request->link[$i],
'news_id' => $request->news_id,

]);
}
}

}

}

}

}

}




sample file here:



<div class="multi-fields">
<div class="multi-field-wrapper">
<div class="col-md-2 col-md-offset-10">
<button type="button" class="add-field btn btn-success"><i class="fa fa-plus"></i>
</button>
</div>

<div class="multi-fields">
<div class="multi-field">
<div class="form-group">
<label for="image">Image</label>
<input type="file" class="form-control" name="image[]" id="image" value="">
</div>
<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" name="title[]" id="title" value="}">
</div>
<button style="width:40px; float:right;" type="button" class="remove-field btn btn-danger form-control col-md-2 col-lg-2"><i
class="fa fa-times"></i>

</button>
<br>
<hr style="border:solid 8px #6ca05a">
</div>
</div>
</div>
</div>



Create .blade




{{-- @extends('layouts.backmaster') --}}
@extends('adminlte::page')

@section('content')

@push('js')
{{-- <script type="text/javascript" src="{{asset('assets/ckeditor/ckeditor.js')}}"></script> --}}

<script>

$('.multi-field-wrapper').each(function() {
var $wrapper = $('.multi-fields', this);
$(".add-field", $(this)).click(function (e) {
var a = $('.multi-field:first-child', $wrapper).clone(true).appendTo($wrapper).find('select').val('').focus();
//a.attr('id','abcd');

});
$('.multi-field .remove-field', $wrapper).click(function () {
if ($('.multi-field', $wrapper).length > 1)
$(this).parent('.multi-field').remove();
});
});

</script>

@endpush







{{-- here --}}


{{-- here --}}
<div class="container">
<div class="row">
<div class="col-md-8 col-lg-8 col-xl-8 col-sm-8 col-xs-8 col-lg-offset-2 col-md-offset-2 col-xs-offset-2 col-sm-offset-2 col-xl-offset-2">
<div class="panel panel-default">
<div class="panel-heading">
<label>Featured In </label>
<a href="{{route('featureds.index')}}" class="btn btn-primary pull-right"> List</a>
</div>

<div class="panel-body">
@if(!isset($featureds->id))
<form method="post" action="{{route('featureds.store')}}" enctype="multipart/form-data" id="valid_form">
<input type="hidden" class="form-control" name="created_by" value="{{Auth::user()->id}}">

@else
<form method="post" action="{{route('featureds.update',$featureds)}}" method="post" enctype="multipart/form-data"
id="valid_form">
<input type="hidden" name="_method" value="put">

<input type="hidden" class="form-control" name="updated_by" value="{{Auth::user()->id}}">
<input type="hidden" class="form-control" name="created_by" value="{{$featureds->created_by}}">
<input type="text" class="form-control" name="news_id" value="{{$news_id}}">
@endif
{{csrf_field()}}


News ID: <input type="text" readonly class="form-control" name="news_id" value="{{$newsid}}">

<div class="multi-fields">
<div class="multi-field-wrapper">
<div class="col-md-2 col-md-offset-10">
<button type="button" class="add-field btn btn-success"><i class="fa fa-plus"></i>
</button>
</div>
<div class="multi-fields">
<div class="multi-field">
<div class="form-group">
<label for="image">Image</label>
<input type="file" class="form-control" name="image[]" id="image" value="{{$featureds->image}}">
@if(isset($featureds->id))
<img src="{{asset('/gallery_upload/'.$featureds->image)}}" height="100"
width="100">
@endif

@if ($errors->has('image'))
<span class="help-block">
<strong>{{ $errors->first('image') }}</strong>
</span>
@endif

</div>

<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" name="title[]" id="title" value="{{$featureds->title}}">
@if ($errors->has('title'))
<span class="help-block">
<strong>{{ $errors->first('title') }}</strong>
</span>
@endif
</div>

<div class="form-group">
<label for="featuredsdate">Featured Date</label>
<input type="date" class="form-control" name="featuredsdate[]" id="featuredsdate"
value="{{$featureds->featuredsdate}}">
@if ($errors->has('featuredsdate'))
<span class="help-block">
<strong>{{ $errors->first('featuredsdate') }}</strong>
</span>
@endif

</div>

<div class="form-group">
<label for="title">Link</label>
<input type="text" class="form-control" name="link[]" id="Link[]" value="{{$featureds->description}}">
@if ($errors->has('link'))
<span class="help-block">
<strong>{{ $errors->first('link') }}</strong>
</span>
@endif

</div>

<button style="width:40px; float:right;" type="button"
class="remove-field btn btn-danger form-control col-md-2 col-lg-2"><i
class="fa fa-times"></i>
</button>

<br>
<hr style="border:solid 8px #6ca05a">
</div>
</div>
</div>

</div>



{{--
<button style="float:right" type="button" class="remove-field btn btn-danger"><i class="fa fa-times"></i>
</button> --}}
{{-- <br> --}}
{{--
<hr style="border:solid 5px #00a65a"> --}}




<div class="form-group">
<input class="btn btn-success" type="submit" name="submit" value="Save Featured ">

</div>

</form>
</div>
</div>
</div>
</div>
</div>
@endsection




Edit.blade


{{-- @extends('layouts.backmaster') --}}
@extends('adminlte::page')

@section('content')

@push('js')
{{-- <script type="text/javascript" src="{{asset('assets/ckeditor/ckeditor.js')}}"></script> --}}

<script>

$('.multi-field-wrapper').hide();

$(document).ready(function() {
$(".more_field").click(function(e) {
{
e.preventDefault();
$('.more_field').hide();
$('.multi-field-wrapper').show();

}
});

});

$('.multi-field-wrapper').each(function() {
var $wrapper = $('.multi-fields', this);
$(".add-field", $(this)).click(function (e) {
var a = $('.multi-field:first-child', $wrapper).clone(true).appendTo($wrapper).find('select').val('').focus();
//a.attr('id','abcd');

});
$('.multi-field .remove-field', $wrapper).click(function () {
if ($('.multi-field', $wrapper).length > 1)
$(this).parent('.multi-field').remove();
});
});

</script>

@endpush







{{-- here --}}


{{-- here --}}
<div class="container">
<div class="row">
<div class="col-md-8 col-lg-8 col-xl-8 col-sm-8 col-xs-8 col-lg-offset-2 col-md-offset-2 col-xs-offset-2 col-sm-offset-2 col-xl-offset-2">
<div class="panel panel-default">
<div class="panel-heading">
<label> Edit featured In </label>
<a href="{{route('featureds.index')}}" class="btn btn-primary pull-right"> List</a>
</div>

<div class="panel-body">
<form method="post" action="{{route('featured.updates')}}" method="post" enctype="multipart/form-data"
id="valid_form">
{{-- <input type="hidden" name="_method" value="put"> --}}

<input type="hidden" class="form-control" name="updated_by" value="{{Auth::user()->id}}">
<input type="hidden" class="form-control" name="created_by" value="">
{{-- <input type="text" class="form-control" name="news_id" value="{{$news_id}}"> --}}
{{csrf_field()}}


News ID: <input type="text" readonly class="form-control" name="news_id" value="{{$news_id}}">

{{-- featured --}}
@foreach($featured as $i=>$f)
<div class="form-group">
<label for="image">Image</label>
<input type="file" class="form-control" name="image[]" id="" value="">
@if(isset($f->id))
<img src="{{asset('/gallery_upload/'.$f->img)}}" height="100"
width="100">
@endif

@if ($errors->has('image'))
<span class="help-block">
<strong>{{ $errors->first('image') }}</strong>
</span>
@endif

</div>

<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" name="title[]" id="title" value="{{$f->title}}">
@if ($errors->has('title'))
<span class="help-block">
<strong>{{ $errors->first('title') }}</strong>
</span>
@endif
</div>

<div class="form-group">
<label for="featureddate">featured Date</label>
<input type="date" class="form-control" name="featureddate[]" id="featureddate"
value="{{$f->date}}">
@if ($errors->has('featureddate'))
<span class="help-block">
<strong>{{ $errors->first('featureddate') }}</strong>
</span>
@endif

</div>

<div class="form-group">
<label for="title">Link</label>
<input type="text" class="form-control" name="link[]" id="Link[]" value="{{$f->link}}">
@if ($errors->has('link'))
<span class="help-block">
<strong>{{ $errors->first('link') }}</strong>
</span>
@endif

</div>
<input type="hidden" name="fid[]" value="{{$f->id}}">
<input type="hidden" name="count" value="{{$i}}">

@endforeach


<button class="more_field" onclick="showfn()">ADD MORE FIELD</button>
{{-- <h1> abba suru bhayo</h1> --}}
{{-- <div id="showonclick"> --}}
<div class="multi-fields">
<div class="multi-field-wrapper">
<div class="col-md-2 col-md-offset-10">
<button type="button" class="add-field btn btn-success"><i class="fa fa-plus"></i>
</button>
</div>
<div class="multi-fields">
<div class="multi-field">
<div class="form-group">
<label for="image">Image</label>
<input type="file" class="form-control" name="image[]" id="image" value="">

@if ($errors->has('image'))
<span class="help-block">
<strong>{{ $errors->first('image') }}</strong>
</span>
@endif

</div>

<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" name="title[]" id="title" value="">
@if ($errors->has('title'))
<span class="help-block">
<strong>{{ $errors->first('title') }}</strong>
</span>
@endif
</div>

<div class="form-group">
<label for="featureddate">Featured Date</label>
<input type="date" class="form-control" name="featureddate[]" id="featureddate"
value="">
@if ($errors->has('featureddate'))
<span class="help-block">
<strong>{{ $errors->first('featureddate') }}</strong>
</span>
@endif

</div>

<div class="form-group">
<label for="title">Link</label>
<input type="text" class="form-control" name="link[]" id="Link[]" value="">
@if ($errors->has('link'))
<span class="help-block">
<strong>{{ $errors->first('link') }}</strong>
</span>
@endif

</div>



<button style="width:40px; float:right;" type="button"
class="remove-field btn btn-danger form-control col-md-2 col-lg-2"><i
class="fa fa-times"></i>
</button>

<br>
<hr style="border:solid 8px #6ca05a">
</div>
</div>
</div>

</div>
{{-- </div> --}}

<div class="form-group">
<input class="btn btn-success" type="submit" name="submit" value="Save featured ">

</div>

</form>
</div>
</div>
</div>
</div>
</div>
@endsection






Main and simple:



@extends('layouts.backmaster')

@section('title', 'data')

@section('content_header')
@stop

@section('csssec')
<style>
.row {
margin-top: 1em;
}

</style>
@stop

@section('jssec')
<script>
$('.multi-field-wrapper').each(function () {
var $wrapper = $('.multi-fields', this);
$(".add-field", $(this)).click(function (e) {
var a = $('.multi-field:first-child', $wrapper).clone(true).appendTo($wrapper).find(
'select').val('').focus();
//a.attr('id','abcd');

});
$('.multi-field .remove-field', $wrapper).click(function () {
if ($('.multi-field', $wrapper).length > 1)
$(this).parent('.multi-field').remove();
});
});

</script>
@stop

@section('content')

<div class="row">
<div
class="col-md-10 col-lg-10 col-xl-10 col-sm-12 col-xs-12 col-lg-offset-1 col-md-offset-1 col-xs-offset-0 col-sm-offset-0 col-xl-offset-1">
<div class="panel panel-default">
<div class="panel-heading padding-bottom">
<div class="row" style="padding:10px">
<table style="width:100%">
<tr>
<th class="headtext">
data
</th>
{{-- <th class=" pull-right">
<a href="{{route('epaper.index')}}" class="btn btn-primary pull-right">data List</a>
</th> --}}
</tr>
</table>

</div>
</div>

<div class="panel-body" style="overflow: auto">
<form action="{{route('epaper.store')}}" method="POST" enctype="multipart/form-data" id="valid_form">


{{csrf_field()}}




<div class="multi-fields">
<div class="multi-field-wrapper">
<div class="col-md-2 col-md-offset-10">
<button type="button" class="add-field btn btn-success"><i class="fa fa-plus"> Add More
Field</i>
</button>
</div>
<br>
<hr>
<br>
<div class="multi-fields">
<div class="multi-field">


<button style="width:40px; float:right;" type="button"
class="remove-field btn btn-danger form-control col-md-2 col-lg-2"><i
class="fa fa-times"></i>
</button>

<br>
</div>
</div>

</div>
<hr style="border:solid 2px black">
<div class="row" style="padding:10px">
<table style="width:100%">
<tr>
<th> </th>
<th class=" pull-right">
<button class="btn btn-success form-control">Submit</button> </th>
</tr>
</table>

</div>
</form>
</div>
</div>
</div>
</div>

@stop




Main



{{-- multifield start --}}
<div class="multi-field-wrapper">
<table class="multi-fields table table-bordered table-hover table-sortable">
<thead>
<th>Name</th>
<th>date</th>
<th>action</th>
</thead>

<tr class="multi-field">

<td>
<input type="text" name="namefor[]">

</td>
<td>
<input type="date" name="datefor[]">

</td>
<td>

<button style="width:40px; float:right;" type="button"
class="remove-field btn "><i class="fa fa-times"></i></button>

</td>



</tr>
</table>
<button type="button" class="add-field custom-button"><i class="fa fa-plus"><span
style="font-family: Montserrat">&nbsp;&nbsp;Add
Day</span></i>
</button>
</div>

{{-- multifield end --}}



Script:


<script>

$('.multi-field-wrapper').each(function () {

var $wrapper = $('.multi-fields', this);
$(".add-field", $(this)).click(function (e) {


var a = $('.multi-field:first-child', $wrapper).clone(true);
a.find("input").val("");


$wrapper.append(a);
});

$('.multi-field .remove-field', $wrapper).click(function () {

if ($('.multi-field', $wrapper).length > 1)
$(this).parent().parent('.multi-field').remove();

});
});



</script>




Comments

Popular posts from this blog

laravel file manager sorting by time default

Ref :  https://github.com/UniSharp/laravel-filemanager/issues/337 To load files order by "time DESC" you can change the code in vendor/unisharp/laravel-filemanager/src/traits/LfmHelpers.php public function sortFilesAndDirectories($arr_items, $sort_type) { if ($sort_type == 'time') { $key_to_sort = 'updated'; } elseif ($sort_type == 'alphabetic') { $key_to_sort = 'name'; } else { $key_to_sort = 'updated'; } return strcmp($a->{$key_to_sort}, $b->{$key_to_sort}); }); return $arr_items; } with public function sortFilesAndDirectories($arr_items, $sort_type) { if ($sort_type == 'time') { $key_to_sort = 'updated'; } elseif ($sort_type == 'alphabetic') { $key_to_sort = 'name'; } else { $key_to_sort = 'updated'; ...

some important points for web developers and hosting

check dns https://www.whatsmydns.net/ https://check-host.net/ https://www.site24x7.com/ping-test.html attacks https://www.computerhope.com/unix/uping.htm https://vitux.com/linux-ping-command/ https://www.howtoforge.com/linux-ping-command/ https://www.poftut.com/linux-ping-command-tutorial-examples/ https://phoenixnap.com/kb/linux-ping-command-examples https://sandilands.info/sgordon/ping-flooding-dos-attack-in-a-virtual-network https://www.geeksforgeeks.org/ping-command-in-linux-with-examples/

Installing Admin LTE in Laravel

step 1:  Reference---  https://hdtuto.com/article/laravel-56-adminlte-bootstrap-theme-installation-example Step 2 : after completion first reference view this link:    https://github.com/JeroenNoten/Laravel-AdminLTE step 3:  For more additional information view this link:   https://github.com/jeroennoten/Laravel-AdminLTE#2-updating Now you are done statically : https://adminlte.io/blog/integrate-adminlte-with-laravel Steps: 1:  composer require jeroennoten/laravel-adminlte 2: 'providers' => [ .... JeroenNoten\LaravelAdminLte\ServiceProvider::class, ], 3: php artisan vendor:publish --provider="JeroenNoten\LaravelAdminLte\ServiceProvider" --tag=assets 5: php artisan vendor:publish --provider="JeroenNoten\LaravelAdminLte\ServiceProvider" --tag=config 6: php artisan vendor:publish --provider="JeroenNoten\LaravelAdminLte\ServiceProvider" --tag=views 7: for admin pannel php artisan ...