Forked from javedLive/Laravel or PHP : dynamic data populate in bootstrap modal
Created
July 6, 2021 16:25
-
-
Save vickymessii/87397abf6c35962b608286fdd7367f77 to your computer and use it in GitHub Desktop.
Dynamic data populate in bootstrap modal Laravel or PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Route: | |
Route::get('message/{id}','AuthorController@getMessage'); | |
Controller: | |
public function getMessage($id) | |
{ | |
$message = DB::table('messages')->where('id',$id)->first(); | |
return view('ajax-message',['message'=>$message]); | |
} | |
Button | |
<a data-toggle="modal" id="getMessage" data-target="#messageBoard" data-url="{{ url('message',['id'=>$row->id])}}" href="#."> Button </a> | |
Dashboard | |
<div class="modal fade" id="messageBoard" role="dialog"> | |
<div class="modal-dialog"> | |
<!-- Modal content--> | |
<div class="modal-content message-modal"> | |
</div> | |
</div> | |
</div> | |
Ajax Part: | |
$(document).on('click', '#getMessage', function(e){ | |
e.preventDefault(); | |
var url = $(this).data('url'); | |
$('.message-modal').html(''); | |
$('#modal-loader').show(); | |
$.ajax({ | |
url: url, | |
type: 'GET', | |
dataType: 'html' | |
}) | |
.done(function(data){ | |
// console.log(data); | |
$('.message-modal').html(''); | |
$('.message-modal').html(data); // load response | |
$('#modal-loader').hide(); // hide ajax loader | |
}) | |
.fail(function(){ | |
$('#dynamic-content').html('<i class="glyphicon glyphicon-info-sign"></i> Something went wrong, Please try again...'); | |
$('#modal-loader').hide(); | |
}); | |
}); | |
ajax-message.blade.php | |
<div class="modal-header"> | |
<button type="button" class="close" data-dismiss="modal">×</button> | |
<h4 class="modal-title">{{$message->message_subject}}</h4> | |
</div> | |
<div class="modal-body"> | |
<div class="popupMessageContainer"> | |
<span class="time_date">{{date('F d, Y', strtotime($message->updated_at))}}, {{date('h:i A', strtotime($message->updated_at))}}</span> | |
<p>{!! $message->message !!} </p> | |
</div> | |
<div class="modal-footer"> | |
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment