Passing data attribute value into blade route - php

I'm building a blog to learn Laravel (5.4.13). In my posts show view I'm looping through all the corresponding post comments. Beside each comment is an edit button and a delete button. For comment editing, I'm attempting to use a modal instead of redirecting to the typical edit view. Currently I'm storing the specific comment data within two data-attributes, and then retrieving those values using jQuery. Then I'm using jQuery again to pass the data into the modal. This is working fine except I'm not sure how to pass the $comment->id into the form route. Any help is much appreciated.
#extends('main')
#section('title', 'View Post')
#section('content')
<div class="row">
<div class="col-md-8">
<h1>{{$post->title}}</h1>
<small>Published: <i class="fa fa-clock-o"></i> {{ $post->created_at->format('M Y, h:i a') }}</small>
<hr class="light-hr">
<p class="lead">{{ str_limit($post->body, $limit = 200, $end = '...') }}</p>
<hr>
<div class="tags">
#foreach($post->tags as $tag)
<span class="label">
{{ $tag->name }}
</span>
#endforeach
</div>
<br>
<br>
{{-- Display comments associated with posts --}}
<h4>Related Posts <i class="fa fa-level-down"></i></h4>
#foreach($post->comments as $comment)
<?php $avatars = array('monsterid', 'identicon', 'wavatar', 'retro'); ?>
<?php $randAvatars = urlencode($avatars[array_rand($avatars)]); ?>
<div class="comments">
<div class="author-info">
<div class="author-img">
<img src={{"https://www.gravatar.com/avatar/".md5(strtolower(trim($comment->email)))."?s=55&d=".$randAvatars}} class="img-circle" alt="user profile image">
</div>
<div class="author-meta">
<b>{{$comment->name}}</b>
made a post.
<h6>Published: <i class="fa fa-clock-o"></i> {{ $comment->created_at->format('M Y, h:i a') }}</h6>
</div>
<div class="comment-controls pull-right">
<button
type="button"
class="btn btn-primary btn-sm fa fa-pencil edit-comment"
data-toggle="modal"
data-comment="{{$comment->comment}}"
data-comment-id="{{$comment->id}}"
data-target="#editComment">
</button>
<button type="button" class="btn btn-danger btn-sm fa fa-trash"></button>
</div>
</div>
<div class="author-comment">
<hr>
<p>{{$comment->comment}}</p>
</div>
</div>
#endforeach
</div>
<div class="col-md-4">
<div class="well">
<dl class="dl-horizontal">
<dt>Created:&nbsp</dt>
<dd> {{ $post->created_at->format('M jS, Y') }}</dd>
<dd><i class="fa fa-clock-o"></i> {{ $post->created_at->format('h:i:s a') }}</dd>
</dl>
<dl class="dl-horizontal">
<dt>Last Updated:&nbsp</dt>
<dd>{{ $post->updated_at->format('M jS, Y') }}</dd>
<dd><i class="fa fa-clock-o"></i> {{ $post->updated_at->format('h:i:s a') }}</dd>
</dl>
<dl class="dl-horizontal">
<dt>Post Slug:&nbsp</dt>
<dd>{{ url('blog/'.$post->slug) }}</dd>
</dl>
<dl class="dl-horizontal">
<dt>Category:&nbsp</dt>
<dd>{{ $post->category->name }}</a></dd>
</dl>
<hr>
<div class="row">
<div class="col-sm-6">
Edit
</div>
<div class="col-sm-6">
<form action="{{ route('posts.destroy', $post->id) }}" method="POST">
<input type="submit" value="Delete" class="btn btn-danger btn-block">
<input type="hidden" name="_token" value="{{ Session::token() }}">
{{ method_field('DELETE') }}
</form>
</div>
<div class="col-sm-12">
Back to <i class="fa fa-long-arrow-right" aria-hidden="true"></i> Posts
</div>
</div>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="editComment" tabindex="-1" role="dialog" aria-labelledby="editCommentLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="editCommentLabel">Edit Comment</h4>
</div>
<div class="modal-body">
<form action="{{route('comments.update', $comment->id)}}" method="POST">
<div class="modal-body">
<div class="form-group">
<textarea name="comment" class="form-control current-comment"></textarea>
<span class="test"></span>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<input type="submit" value="Save Changes" class="btn btn-primary">
<input type="hidden" name="_token" value="{{ Session::token() }}">
{{ method_field('PUT') }}
</div>
</form>
</div>
</div>
</div>
</div>
#section('scripts')
<script>
$('.edit-comment').on('mousedown', function(){
var comment = $(this).attr('data-comment');
var comment_id = $(this).attr('data-comment-id');
$('.current-comment').html(comment);
$('.test').html(comment_id);
});
</script>
#endsection
#endsection
// Comments Routes
Route::post('comments/{id}', ['uses' => 'CommentsController#store', 'as' => 'comments.store']);
Route::put('comments/{id}', ['uses' => 'CommentsController#update', 'as' => 'comments.update']);

You're almost there. I would suggest that you don't need to pass the {id} since you use the [PUT] method to pass the data in your {form}.
We can set a new hidden {input} type inside your {form} (e.g input[name="edit_comment_id"]) and remove the request parameter from the url in your form's {action} attribute.
Like this:
<form action="{{route('comments.update')}}" method="POST" id="update-comment">
<div class="modal-body">
<div class="form-group">
<input type="hidden" name="edit_comment_id" /> //place the {id} in here
<textarea name="comment" class="form-control current-comment"></textarea>
<span class="test"></span>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<input type="submit" value="Save Changes" class="btn btn-primary">
<input type="hidden" name="_token" value="{{ Session::token() }}">
{{ method_field('PUT') }}
</div>
</form>
Then in your {scripts} section:
$('.edit-comment').on('mousedown', function(){
var comment = $(this).attr('data-comment');
var comment_id = $(this).attr('data-comment-id'); // (e.g 12)
var oFormUpdateComment = $('#update-comment'); //add an {id} attribute on your form name 'update-comment' as given above.
oFormUpdateComment.find('input[name="edit_comment_id"]').val(comment_id);
});
And since we didn't pass a request parameter next to the 'comments' url anymore, You will update your [routes.php] like this:
Route::post('comments', ['uses' => 'CommentsController#store', 'as' => 'comments.store']);
Route::put('comments', ['uses' => 'CommentsController#update', 'as' => 'comments.update']);
Then in your [CommentsController], Since you already know how to get those values:
use Illuminate\Support\Facades\Input;
class CommentsController extends Controller
{
protected function store()
{
print_r('<pre>');
var_dump(Input::get('edit_comment_id'));
}
protected function update()
{
print_r('<pre>');
var_dump(Input::all());
}
}
Hope this helps for your case.

I was reluctant to answer this myself but was able to get it to work after rethinking my approach. Instead of trying to alter the blade url in the form somehow, I left the action attribute blank and built the url dynamically when the event fired. So as I did before, I grabbed the data from the data attributes, but instead of trying to alter the blade tag in the form, the url is built and then added to the action attribute. This thread was a great help. I posted my updated code incase it helps anyone.
#extends('main')
#section('title', 'View Post')
#section('content')
<div class="row">
<div class="col-md-8">
<h1>{{$post->title}}</h1>
<small>Published: <i class="fa fa-clock-o"></i> {{ $post->created_at->format('M Y, h:i a') }}</small>
<hr class="light-hr">
<p class="lead">{{ str_limit($post->body, $limit = 200, $end = '...') }}</p>
<hr>
<div class="tags">
#foreach($post->tags as $tag)
<span class="label">
{{ $tag->name }}
</span>
#endforeach
</div>
<br>
<br>
{{-- Display comments associated with posts --}}
<h4>Related Posts <i class="fa fa-level-down"></i></h4>
#foreach($post->comments as $comment)
<?php $avatars = array('monsterid', 'identicon', 'wavatar', 'retro'); ?>
<?php $randAvatars = urlencode($avatars[array_rand($avatars)]); ?>
<div class="comments">
<div class="author-info">
<div class="author-img">
<img src={{"https://www.gravatar.com/avatar/".md5(strtolower(trim($comment->email)))."?s=55&d=".$randAvatars}} class="img-circle" alt="user profile image">
</div>
<div class="author-meta">
<b>{{$comment->name}}</b>
made a post.
<h6>Published: <i class="fa fa-clock-o"></i> {{ $comment->created_at->format('M Y, h:i a') }}</h6>
</div>
<div class="comment-controls pull-right">
{{-- Store comment specific data to built URL for modal --}}
<button
type="button"
class="btn btn-primary btn-sm fa fa-pencil edit-comment"
data-toggle="modal"
data-comment="{{$comment->comment}}"
data-comment-id="{{$comment->id}}"
data-target="#editComment">
</button>
<button type="button" class="btn btn-danger btn-sm fa fa-trash" ></button>
</div>
</div>
<div class="author-comment">
<hr>
<p>{{$comment->comment}}</p>
</div>
</div>
#endforeach
</div>
<div class="col-md-4">
<div class="well">
<dl class="dl-horizontal">
<dt>Created:&nbsp</dt>
<dd> {{ $post->created_at->format('M jS, Y') }}</dd>
<dd><i class="fa fa-clock-o"></i> {{ $post->created_at->format('h:i:s a') }}</dd>
</dl>
<dl class="dl-horizontal">
<dt>Last Updated:&nbsp</dt>
<dd>{{ $post->updated_at->format('M jS, Y') }}</dd>
<dd><i class="fa fa-clock-o"></i> {{ $post->updated_at->format('h:i:s a') }}</dd>
</dl>
<dl class="dl-horizontal">
<dt>Post Slug:&nbsp</dt>
<dd>{{ url('blog/'.$post->slug) }}</dd>
</dl>
<dl class="dl-horizontal">
<dt>Category:&nbsp</dt>
<dd>{{ $post->category->name }}</a></dd>
</dl>
<hr>
<div class="row">
<div class="col-sm-6">
Edit
</div>
<div class="col-sm-6">
<form action="{{ route('posts.destroy', $post->id) }}" method="POST">
<input type="submit" value="Delete" class="btn btn-danger btn-block">
<input type="hidden" name="_token" value="{{ Session::token() }}">
{{ method_field('DELETE') }}
</form>
</div>
<div class="col-sm-12">
Back to <i class="fa fa-long-arrow-right" aria-hidden="true"></i> Posts
</div>
</div>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="editComment" tabindex="-1" role="dialog" aria-labelledby="editCommentLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="editCommentLabel">Edit Comment</h4>
</div>
<div class="modal-body">
<form id="comment-edit-modal" action="" method="POST">
<div class="modal-body">
<div class="form-group">
<textarea name="comment" class="form-control current-comment"></textarea>
<span class="test"></span>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<input type="submit" value="Save Changes" class="btn btn-primary">
<input type="hidden" name="_token" value="{{ Session::token() }}">
{{ method_field('PUT') }}
</div>
</form>
</div>
</div>
</div>
</div>
#section('scripts')
<script>
$('.edit-comment').on('mousedown', function(){
var comment = $(this).attr('data-comment');
$('.current-comment').html(comment);
var comment_id = $(this).attr('data-comment-id');
var form = $('#comment-edit-modal')
// Set current URL
var comment_edit_URL = {!! json_encode(url('/comments')) !!} + '/' + comment_id;
// Append currrent URL
form.attr('action', comment_edit_URL);
});
</script>
#endsection
#endsection

Related

Edit comment works only for first comment

I had a different page for edit comments - comments/{$id}/edit and I'm trying to add this to a modal in the same page with my comment.The problem is , when I open my modal, I get only first comment of 5, even if I have buttons on all comments.What's happening here?
My view + modal
<div class="col-md-12">
#foreach($post->comments()->latest()->paginate(5) as $comment)
<div class="media g-mb-30">
<img class="d-flex g-width-50 g-height-50 rounded-circle g-mt-3 g-mr-20" src="/storage/{{ $comment->image }}" alt="Image Description">
<div class="media-body g-brd-around g-brd-gray-light-v4 g-pa-30" style="margin-right: -35px">
<div class="g-mb-15">
<h5 class="d-flex justify-content-between align-items-center h5 g-color-gray-dark-v1 mb-0">
<span class="d-block g-mr-10">{{ $comment->username }}
<span class="g-color-black-opacity-0_7 g-pos-rel g-top-2 mx-2">·</span>
<span class="g-color-gray-dark-v4 g-font-size-12">{{ $comment->created_at }}</span>
</span>
<a class="u-tags-v1 g-font-size-12 g-brd-around g-brd-gray-light-v4 g-bg-primary--hover g-brd-primary--hover g-color-black-opacity-0_8 g-color-white--hover rounded g-py-6 g-px-15" href="/profile/{{ $comment->user_id }}">Author</a>
</h5>
</div>
<p>{{$comment->comment}}</p>
<ul class="list-inline d-sm-flex my-0">
#can('update', $post->user->profile)
<li class="list-inline-item ml-auto">
<a href="#" class="u-link-v5 g-color-gray-dark-v4 g-color-primary--hover" data-toggle="modal" data-target="#exampleModal2">
<i class="icon-note g-pos-rel g-top-1 g-mr-3"></i>
Edit comment
</a>
<!-- Modal -->
<div class="modal fade" id="exampleModal2" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="col-md-8 colm-d-offset-2">
<h1>edit comment</h1>
{{ Form::model($comment, ['route' => ['comments.update', $comment->id] , 'method' => 'PUT']) }}
{{ Form::label('comment', "Comment:") }}
{{ Form::textarea('comment', null, ['class' => 'form-control']) }}
{{ Form::submit('Update Comment', ['class' => 'btn btn-success btn-xs']) }}
{{ Form::close() }}
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</li>
<li class="list-inline-item ml-auto">
<a class="u-link-v5 g-color-gray-dark-v4 g-color-primary--hover" href="/deleteComment/{{$comment->id}}">
<i class="icon-note g-pos-rel g-top-1 g-mr-3"></i>
Delete comment
</a>
</li>
#endcan
</ul>
</div>
</div>
#endforeach
{{ $post->comments()->latest()->paginate(5)->links() }}
</div>
</div>
</div>
</div>
</div>
</div>
**Here is my old route : **
Route::get('/comments/{id}/edit', ['uses' => 'CommentsController#edit', 'as' => 'comments.edit']);
My controller
public function edit($id)
{
$comment = Comment::find($id);
return view ('comments.edit')->withComment($comment);
}
public function update(Request $request, $id)
{
$comment = Comment::find($id);
$this->validate($request, array('comment' => 'required'));
$comment->comment = $request->comment;
$comment->save();
Session::flash('success', 'Comment updated');
return redirect('/post/' . $comment->post->id);
}
you must set id="{!! $comment->id !!}
<a id="{!! $comment->id !!}" href="#" class="u-link-v5 g-color-gray-dark-v4 g-color-primary--hover" data-toggle="modal" data-target="#exampleModal2">
<i class="icon-note g-pos-rel g-top-1 g-mr-3"></i>
Edit comment
</a>
and if you want access to id by $(this).attr("id"); and send this to modal or ajaxController

showing data in modal in laravel

I'm using Laravel and I'm trying to delete or update the services on my platform
I'm using confirmation modal for that..
but when I delete or or update or show content in the modal it always works on the first row only...
that's the code
#foreach ($services as $service)
<div class="card-content">
<div class="row">
<div class="col l4">
<div class="row">
<div class="col s12">
<span>
<a class="btn-floating btn-large modal-trigger tooltipped waves-effect waves-light red hoverable"
data-position="left"
data-tooltip="Supprimer ce service"
data-text-color="grey-text"
href="#modal1">
<i class="material-icons">delete</i>
</a>
</span>
<span>
<a class="btn-floating btn-large modal-trigger tooltipped waves-effect waves-light green"
data-position="right"
data-tooltip="Modifier ce service"
data-delay="20"
href="#modal2">
<i class="material-icons" href="#modal2">update</i>
</a>
</span>
</div>
</div>
<div id="modal1" class="modal">
<div class="modal-content">
<div class="row">
<div class="col s6">
<p>Voulez vous vraiment supprimer ce service ?</p>
</div>
<div class="col s6">
<form action="/Services/{{$service->id}}" method="POST">
{{ csrf_field() }}
#method('DELETE')
<span>
<input type="submit" class="btn purple hoverable waves effect" value="supprimer">
</span>
<span>
Non
</span>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
#endforeach
Invoke modal via jquery like
$('#myModal').modal('show');
$('#myModal').modal('hide');
In Loop Anchor
<span>
<a class="btn-floating btn-large modal-trigger tooltipped waves-effect waves-light green modalclick"
data-position="right"
data-tooltip="Modifier ce service"
data-delay="20"
data-id="<?php echo $service->id; ?>"
href="javascript:void(0)"
>
<i class="material-icons" href="#modal2>update</i>
</a>
</span>
$(".modalclick").click(function(){
var current_id = $(this).attr("data-id");
//use jquery below to change modal form action with id
$('#myModal').modal('show');
});
Define modal popup for each record if you in loop if you dont want to use jquery that get and service id and pass into modal form.
<?php $a = 1; ?>
#foreach ($services as $service)
<div class="card-content">
<div class="row">
<div class="col l4">
<div class="row">
<div class="col s12">
<span> <a class="btn-floating btn-large modal-trigger tooltipped waves-effect waves-light red hoverable" data-position="left" data-tooltip="Supprimer ce service" data-text-color="grey-text" href="#modal{{$a}}"><i class="material-icons">delete</i></a></span>
<span> <a class="btn-floating btn-large modal-trigger tooltipped waves-effect waves-light green" data-position="right" data-tooltip="Modifier ce service" data-delay="20" href="#modal2"><i class="material-icons" href="#modal2">update</i></a></span>
</div>
</div>
<div id="modal{{$a}}" class="modal">
<div class="modal-content">
<div class="row">
<div class="col s6">
<p>Voulez vous vraiment supprimer ce service ?</p>
</div>
<div class="col s6">
<form action="/Services/{{$service->id}}" method="POST">
{{ csrf_field() }}
#method('DELETE')
<span>
<input type="submit" class="btn purple hoverable waves effect" value="supprimer">
</span>
<span>
Non
</span>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php $a++; ?>
#endforeach
See if it is work for you.

Links and buttons don't work on small and extra small screens in bootstrap grid

I have created a view that shows 2 columns on medium and large screens but only 1 column on small and extra small screens. I'm using the push and pull classes from bootstrap to reorder my panels at different screen sizes.
My problem is that on small and extra small screen sizes some of my links and buttons are not clickable.
I have followed this thread Links in bootstrap grid stop working in small screen mode. It says the problem is that the links are floated, resulting in a height of 0 for the parent container.
I have tried using the "clearfix" class. I've also created my own class using overflow:auto and another using overflow:hidden and none of these work.
I have never had this problem before but this is the first time I've used push/pull. Would you take a look at my code and see if you can spot the problem?
<div class="container">
<!--*********************************Modal for notes**********************************************************-->
<div class="modal fade" id="myModal" name="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h3 class="modal-title" id="myModalLabel">Notes</h3>
</div>
<div class="modal-body">
<form method="post" action="/notes/save" role="form" name="new_note">
{!! csrf_field() !!}
<div class="form-group">
<label for="note">Type a new note for this client. (The current date will be automatically added.)</label>
<textarea class="form-control" rows="15" name="note" id="note" required></textarea>
<input type="hidden" name="ind_id" value="{{ $id }}">
<input type="hidden" name="timestamp" id="timestamp">
</div>
</div>
<div class="modal-footer">
<input type="submit" class="btn btn-primary" value="Save Changes" onclick="this.form.timestamp.value=Date.now()">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</form>
</div>
</div>
</div>
</div>
<!--***********************************End modal code***********************************************************-->
<div class="row">
<div class="col-md-8 col-md-push-4 col-lg-9 col-lg-push-3">
<!--************************************Name and Address********************************************************-->
<div class="panel panel-primary">
<div class="panel-heading">Name and Address</div>
<div class="panel-body">
<address class="col-md-6">
<strong>{{ $ind->name }}</strong><br>
#if ($ind->MailingStreet)
{{ $ind->MailingStreet }}<br>
#endif
#if ($ind->MailingCity || $ind->MailingState || $ind->MailingPostalCode)
{{ $ind->MailingCity . ", " . $ind->MailingState . " " . $ind->MailingPostalCode }}
#endif
</address>
<address class="col-md-6">
#if ($ind->OtherStreet || $ind->OtherCity || $ind->OtherState || $ind->OtherPostalCode)
<strong>Other Address</strong><br>
#endif
#if ($ind->OtherStreet)
{{ $ind->OtherStreet }}<br>
#endif
#if ($ind->OtherCity || $ind->OtherState || $ind->OtherPostalCode)
{{ $ind->OtherCity . ", " . $ind->OtherState . " " . $ind->OtherPostalCode }}
#endif
</address>
</div>
</div>
<!--*******************************************End Name and Address***************************************-->
<!--*******************************************Contact Info***********************************************-->
<div class="panel panel-danger">
<div class="panel-heading">Contact Info</div>
<div class="panel-body">
#if ($ind->Cell_Phone)
<div class="col-md-5 col-sm-6"><strong>Cell Phone</strong></div>
<div class="col-md-7 col-sm-6">{{ $ind->Cell_Phone }}</div>
#endif
#if ($ind->Spouse_Cell_Phone)
<div class="col-md-5 col-sm-6"><strong>Spouse Cell Phone</strong></div>
<div class="col-md-7 col-sm-6">{{ $ind->Spouse_Cell_Phone }}</div>
#endif
#if ($ind->Business_Phone)
<div class="col-md-5 col-sm-6"><strong>Business Phone</strong></div>
<div class="col-md-7 col-sm-6">{{ $ind->Business_Phone }}</div>
#endif
#if ($ind->Spouse_Business_Phone)
<div class="col-md-5 col-sm-6"><strong>Spouse Business Phone</strong></div>
<div class="col-md-7 col-sm-6">{{ $ind->Spouse_Business_Phone }}</div>
#endif
#if ($ind->HomePhone)
<div class="col-md-5 col-sm-6"><strong>Home Phone</strong></div>
<div class="col-md-7 col-sm-6">{{ $ind->HomePhone }}</div>
#endif
#if ($ind->Fax)
<div class="col-md-5 col-sm-6"><strong>Fax</strong></div>
<div class="col-md-7 col-sm-6">{{ $ind->Fax }}</div>
#endif
#if ($ind->Email)
<div class="col-md-5 col-sm-6"><strong>Email</strong></div>
<div class="col-md-7 col-sm-6">{{ $ind->Email }}</div>
#endif
#if ($ind->Spouse_Email)
<div class="col-md-5 col-sm-6"><strong>Spouse Email</strong></div>
<div class="col-md-7 col-sm-6">{{ $ind->Spouse_Email }}</div>
#endif
#if ($ind->Return_Type)
<div class="col-md-5 col-sm-6"><strong>Return Type</strong></div>
<div class="col-md-7 col-sm-6">{{ $ind->Return_Type }}</div>
#endif
</div>
</div>
<!--*********************************************End Contact Info******************************************-->
</div>
<div class="col-sm-12 col-md-4 col-md-pull-8 col-lg-3 col-lg-pull-9 pull-right">
<!--*******************************************Options***********************************************************-->
<ul class="list-group">
<li class="list-group-item">
<i class="fa fa-pencil-square-o"></i> Edit Client
</li>
<li class="list-group-item">
<i class="fa fa-times"></i> Delete Client
</li>
<li class="list-group-item">
<button type="button" class="btn btn-success btn-block no-print" data-toggle="modal" data-target="#myModal"><i class="fa fa-sticky-note-o"></i> Add Note</button>
</li>
<!--********************Link Form*****************************************-->
<li class="list-group-item">
<form action="/links/save" method="post" class="form-inline">
{!! csrf_field() !!}
<div class="input-group btn-block">
<input id="autocomplete" type="text" class="form-control autocomplete no-print" name="client" placeholder="Add link..." required>
<input id="autocomplete-value" type="hidden" name="autocomplete-value" class="autocomplete-value">
<input id="ind_id" name="ind_id" type="hidden" value="{{ $id }}">
<span class="input-group-btn">
<button type="submit" class="btn btn-success no-print" style="height:36px;">Go</button>
</span>
</div>
</form>
</li>
<!--***********************End Link form*************************************-->
</ul>
<!--***************************************End Options*********************************************************-->
<!--************************************************Routing sheet starts here*********************************************************-->
#if(isset($routing_sheet))
<div class="panel panel-info" id="2015_routing_sheet">
<div class="panel-heading" role="tab" id="headingOne">2015 Tax Return</div>
<ul class="list-group">
#foreach($routing_sheet as $r)
<form action='/individuals/tax_return_2015' method='post'>
{!! csrf_field() !!}
#if($r->user_name)
<li class="list-group-item" style="padding: 5px 5px 5px 5px;">
<div>
<button
type='submit'
class='btn btn-success btn-xs'
name='button'
value="Clear"
onclick="return confirm('Are you sure you want to clear this event?')">
<i class="fa fa-check" aria-hidden="true"></i>
</button>
<strong>{{ $r->name }}</strong>
</div>
<div>
{{ $r->user_name }}
{{ $r->date ? date('m/d/Y h:i a', strtotime($r->date)) : '' }}
</div>
<input type='hidden' name='routing_events_id' id='routing_events_id' value='{{ $r->id }}'>
<input type='hidden' name='routing_data_id' id='routing_data_id' value='{{ $r->routing_data_id }}'>
</li>
#else
<li class="list-group-item" style="padding: 5px 5px 5px 5px;">
<button
type='submit'
class='btn btn-danger btn-xs'
name='button'
value="Done"
onclick='this.form.timestamp.value=Date.now()'>
<i class="fa fa-square-o" aria-hidden="true"></i>
</button>
<strong>{{ $r->name }}</strong>
{{ $r->user_name }}
{{ $r->date ? date('m/d/Y h:i a', strtotime($r->date)) : '' }}
<input type='hidden' name='routing_events_id' id='routing_events_id' value='{{ $r->id }}'>
<input type='hidden' name='routing_data_id' id='routing_data_id' value='{{ $r->routing_data_id }}'>
</li>
#endif
<input id="ind_id" name="ind_id" type="hidden" value="{{ $id }}">
<input type="hidden" name="timestamp" id="timestamp">
</form>
#endforeach
</ul>
</div>
#endif
<!--*********************************************Routing Sheet ends here***********************************************-->
</div>
<div class="col-md-8 col-md-push-4 col-lg-9 col-lg-push-3">
<!--*******************************************Links**********************************************************-->
<div class="panel panel-warning">
<div class="panel-heading">Links</div>
<ul class="list-group">
<!--******************Start of displaying links*****************-->
#if(count($links_ind))
#foreach($links_ind as $link)
<li class="list-group-item">
<div class="row">
<div class="col-md-1 col-xs-1">
<a
href='/links/delete/{{ $link->link_id }}'
class='btn btn-danger btn-sm no-print'
onclick="return confirm ('Are you sure you want to delete this link?')">
<i class="fa fa-times"></i>
</a>
</div>
<div class="col-md-11 col-xs-11">
<div class="col-md-4 col-sm-5"><strong>Name</strong></div>
<div class="col-md-8 col-sm-7">
<a href='/individuals/{{ $link->ind_id }}'>{{ $link->FirstName.' '.$link->LastName }}</a>
</div>
#if ($link->Business_Phone)
<div class="col-md-4 col-sm-5"><strong>Business Phone</strong></div>
<div class="col-md-8 col-sm-7">{{ $link->Business_Phone }}</div>
#endif
#if ($link->Cell_Phone)
<div class="col-md-4 col-sm-5"><strong>Cell Phone</strong></div>
<div class="col-md-8 col-sm-7">{{ $link->Cell_Phone }}</div>
#endif
#if ($link->Spouse_Cell_Phone)
<div class="col-md-4 col-sm-5"><strong>Spouse Cell Phone</strong></div>
<div class="col-md-8 col-sm-7">{{ $link->Spouse_Cell_Phone }}</div>
#endif
#if ($link->HomePhone)
<div class="col-md-4 col-sm-5"><strong>Home Phone</strong></div>
<div class="col-md-8 col-sm-7">{{ $link->HomePhone }}</div>
#endif
</div>
</div>
</li>
#endforeach
#endif
#if(count($links_bus))
#foreach($links_bus as $link)
<li class="list-group-item">
<div class="row">
<div class="col-md-1 col-xs-1">
<a href='/links/delete/{{ $link->link_id }}'
class='btn btn-danger btn-sm no-print'
onclick="return confirm ('Are you sure you want to delete this link?')">
<i class="fa fa-times"></i>
</a>
</div>
<div class="col-md-11 col-xs-11">
<div class="col-md-4 col-sm-5"><strong>Name</strong></div>
<div class="col-md-7 col-sm-7">
<a href='/businesses/{{ $link->bus_bus_id }}'>{{ $link->company_name }}</a>
</div>
#if ($link->business_phone)
<div class="col-md-4 col-sm-5"><strong>Business Phone</strong></div>
<div class="col-md-7 col-sm-7">{{ $link->business_phone }}</div>
#endif
#if ($link->cell_phone)
<div class="col-md-4 col-sm-5"><strong>Cell Phone</strong></div>
<div class="col-md-7 col-sm-7">{{ $link->cell_phone }}</div>
#endif
#if ($link->fax)
<div class="col-md-4 col-sm-5"><strong>Fax</strong></div>
<div class="col-md-7 col-sm-7">{{ $link->fax }}</div>
#endif
#if ($link->email)
<div class="col-md-4 col-sm-5"><strong>Email</strong></div>
<div class="col-md-7 col-sm-7">{{ $link->email }}</div>
#endif
</div>
</div>
</li>
#endforeach
#endif
</ul>
</div>
<!--*******************************************************End of displaying links*************************************************-->
<!--*****************************************start of displaying notes************************************************-->
<div class="panel panel-success">
<div class="panel-heading">Notes</div>
<ul class="list-group">
#if(count($notes))
<!--***********************************Modal for each note*******************************************-->
#foreach($notes as $note)
<div class='modal fade'
id='myModal{{ $note->id }}'
name='myModal{{ $note->id }}'
tabindex='-1'
role='dialog'
aria-labelledby='myModalLabel'>
<div class='modal-dialog modal-lg' role='document'>
<div class='modal-content'>
<div class='modal-header'>
<button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>×</span></button>
<h3 class='modal-title' id='myModalLabel'>Edit Note</h3>
</div>
<form method='post' action='/notes/save' role='form' name='new_note'>
{!! csrf_field() !!}
<div class='modal-body'>
<div class='form-group'>
<label for='note'>Edit the note and save your changes.</label>
<textarea class='form-control' rows='15' name='note' id='note' required>{{ $note->note }}</textarea>
<input type='hidden' name='ind_id' id='ind_id' value="{{ $id }}">
<input type='hidden' name='note_id' id='note_id' value="{{ $note->id }}">
<input type='hidden' name='timestamp' id='timestamp'>
</div>
</div>
<div class='modal-footer'>
<input type='submit' class='btn btn-primary' value='Save Changes' onclick='this.form.timestamp.value=Date.now()'>
<button type='button' class='btn btn-default' data-dismiss='modal'>Close</button>
</div>
</form>
</div>
</div>
</div>
<!--*****************************************End Modal for each note****************************************-->
<li class="list-group-item">
<div class="row">
<div class="col-lg-2 col-md-3 col-sm-2 col-xs-4">
<button type='button'
class='btn btn-warning no-print'
data-toggle='modal'
data-target='#myModal{{ $note->id }}'
>
<i class="fa fa-pencil-square-o"></i>
</button>
<a href='/notes/delete/{{ $note->id }}'
class='btn btn-danger no-print'
onclick="return confirm('Are you sure you want to delete this note?')"
><i class="fa fa-times"></i></a>
</div>
<div class="col-lg-2 col-md-3 col-sm-6 col-xs-8">{{ $note->user->name . ' ' . $note->user->last_name }}<br>{{ $note->timestamp->format('n/j/Y') }}</div>
<div class="col-lg-8 col-md-6 col-sm-12"><pre class="pre-note">{{ $note->note }}</pre></div>
</div>
</li>
#endforeach
#endif
</ul>
</div>
<!--******************************************end of displaying notes***************************************************-->
<!--*****************************************start of displaying invoices***********************************************
<div class="panel panel-success">
<div class="panel-heading">
<h3 class="panel-title">Invoices</h3>
</div>
<div class="panel-body">
<ol>
#foreach($invoices as $invoice)
<li><a href='/invoice/pdf/{{ $invoice->id }}'>{{ date('m-d-Y', strtotime($invoice->date)) }}</a> {{ '$' . $invoice->amount }}</li>
#endforeach
</ol>
</div>
</div>
<!****************************************end of displaying invoices**************************************************-->
</div>
<script>
//This encodes the PHP array as JSON so that the autocomplete.js script can use it
var dataTwo = {!! $dataTwo !!};
</script>
</div>
</div>
Thank you
Jason
I didn't go through your whole code, but here is what I think is the problem. if for example you have a situation where you need to show
different number of columns on different screen sizes with bootstrap, please be specific with all column sizes. Don't let bootstrap guess.
here is what I mean:
for example you have this code:
<div class="col-lg-2 col-md-3 col-sm-2 col-xs-4">
<button type='button'
class='btn btn-warning no-print'
data-toggle='modal'
data-target='#myModal{{ $note->id }}'
>
<i class="fa fa-pencil-square-o"></i>
</button>
<a href='/notes/delete/{{ $note->id }}'
class='btn btn-danger no-print'
onclick="return confirm('Are you sure you want to delete this note?')"
><i class="fa fa-times"></i></a>
</div>
<div class="col-lg-2 col-md-3 col-sm-6 col-xs-8">{{ $note->user->name . ' ' . $note->user->last_name }}<br>{{ $note->timestamp->format('n/j/Y') }}</div>
<div class="col-lg-8 col-md-6 col-sm-12"><pre class="pre-note">{{ $note->note }}</pre></div>
You can see that you have specified the following for extra small screens: "col-xs-4", and "col-xs-8" for the first and second div's respectevely. What
about the third div? You have implied that it is "col-xs-12". I am afraid you will have to explicitely say that it is "col-xs-12".
so if you were to change your code to :
<div class="col-lg-2 col-md-3 col-sm-2 col-xs-4">
<button type='button'
class='btn btn-warning no-print'
data-toggle='modal'
data-target='#myModal{{ $note->id }}'
>
<i class="fa fa-pencil-square-o"></i>
</button>
<a href='/notes/delete/{{ $note->id }}'
class='btn btn-danger no-print'
onclick="return confirm('Are you sure you want to delete this note?')"
><i class="fa fa-times"></i></a>
</div>
<div class="col-lg-2 col-md-3 col-sm-6 col-xs-8">{{ $note->user->name . ' ' . $note->user->last_name }}<br>{{ $note->timestamp->format('n/j/Y') }}</div>
<div class="col-lg-8 col-md-6 col-sm-12 col-xs-12"><pre class="pre-note">{{ $note->note }}</pre></div>
It is going to work without any problem. Notice the explicit "col-xs-12" for the last div. The problem is on xtra small screens the first and second div's are floated left because they have "col-xs-..." whilst the third div is not floated and ends up causing chaos!
Have fun!!

Laravel 5.2 LengthAwarePaginator does not show any result on navigating to next page

I'm using a LengthAwarePaginator which paginates the results obtained from Twitter api. The first page works just fine but as i navigate to the any other page through the paginated links, it does not give any result.
Routes:
Route::any('/search', ['uses' => 'TweetController#getSearch', 'as' => 'search']);
TweetController:
public function getSearch(Request $request)
{
$currentPage = LengthAwarePaginator::resolveCurrentPage();
$perPage = 6;
$tweetArray = Twitter::getUserTimeline(['screen_name' => $request['search'], 'count' => $request['count']]);
$tweetPerPage = array_slice($tweetArray, (($currentPage-1) * $perPage), $perPage, true);
$tweets = new LengthAwarePaginator($tweetPerPage, count($tweetArray), $perPage, $currentPage, ['path' => $request->url()]);
return view('tweets', ['tweets' => $tweets]);
}
tweet.blade.php:
<div class="row">
<form action="{{ route('search') }}" method="post">
<div class="col-md-5 col-md-offset-3">
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">#</span>
<input type="text" class="form-control" placeholder="Search using Twitter Handle" name="search" aria-describedby="basic-addon1">
<div class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="number">How many?</span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right">
<li>10</li>
<li>20</li>
<li>30</li>
</ul>
</div>
</div>
</div>
<div class="col-md-1">
<button type"submit" class="btn btn-info">Search</button>
</div>
<input type="hidden" name="count" value="10">
</form>
</div>
<script src="js/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$('.dropdown-menu > li').click(function() {
var cnt = $(this).children().html();
$('input[type="hidden"]').val(cnt);
$('.number').html(cnt);
});
});
</script>
<hr />
#foreach($tweets as $tweet)
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="well">
<div class="media">
<div class="media-left">
<a href="#">
<img class="media-object" src="{{ $tweet->user->profile_image_url }}">
</a>
</div>
<div class="media-body">
<h4 class="media-heading">{{ $tweet->user->name }}</h4>
{{ $tweet->text }}
</div>
<small class="pull-right">{{ Twitter::ago($tweet->created_at) }}</small>
</div>
</div>
</div>
</div>
#endforeach
<div class="row">
<div class="text-center">
{!! $tweets->render() !!}
</div>
</div>

Laravel button does not link to route

#extends('layout')
#section('content')
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h1>{{ $id->title }}</h1>
<ul class="list-group">
#foreach($id->notes as $note)
<li class="list-group-item">
{{ $note->body }}
<span class="pull-right">
<button href="/notes/{{ $note->id }}/edit" type="button" class="label label-default pull-xs-right">Edit</button>
</span>
</li>
#endforeach
</ul>
<hr>
<h3>Add a New Note</h3>
<div class="form-group">
<form method="post" action="/cards/{{ $id->id }}/notes">
<div class="form-group">
<textarea name="body" class="form-control"></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Add Note</button>
</div>
</form>
</div>
</div>
</div>
#stop
The button in the foreach loop has the correct link, /note/id/edit. I can type that into chrome and go to the edit page. However, the button does not head there. I just see the click animation. Why would this be?
Button element does not have the href attribute so you can either wrap it in a link tag like this. and this is the easiest way
<a href="{{"/notes/". $note->id. "/edit"}}" >
<button type="button" class="label label-default pull-xs-right">Edit</button
></a>
or you can wrap it in a form element and set the action attribute to your desired link like this.
<Form method="get" action="{{"/notes/". $note->id. "/edit"}}">
<button type="submit" class="label label-default pull-xs-right">Edit</button>
</Form>
the 3rd way is to use javascript and onclick listener.
use <a></a> tag, instead of button, and set type="button"
Check Any

Categories