how to call dialog window Laravel 5 - php

I do this project using Laravel 5.
<td> {{ $ethenic->ethenicCode }} </td>
This is my Blade view file part of code. I want when I click this code open dialog box.
This is my div.
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="btn btn-default" style='float: right;' data-dismiss="modal"><span class="glyphicon glyphicon-remove-circle"></span></button>
</span>
</span>
<h4 class="modal-title">Member Ethnicity Details</h4>
</div>
<!-- text input -->
<div class="modal-body">
{!! Form::label('e_code', 'Ethnicity Code: '); !!}
{!! Form::text('ethenicity_code', null, ['class' => 'form-control', 'id' => 'ethenicity_code', 'placeholder' => 'Enter Ethnicity Code here','disabled' => 'disabled']); !!}
{!! Form::label('e_name', 'Ethnicity Name: '); !!}
{!! Form::text('ethenicity_name', null, ['class' => 'form-control', 'id' => 'ethenicity_name', 'placeholder' => 'Enter Ethnicity Name here' ,'disabled' => 'disabled']); !!}
</div>
</div>
</div>
This both code in same x.blade.php file. Very beginning I use following code to call this div and working fine.
<td> {!! 'Event Name '.$i !!} </td>
but now I am try different way with in my Controller method to call this div id, but I couldn't.
Controller class code:
public function show($id) {
//
$designation = Designation::find($id);
return view('x.blade.php#myModal', compact('designation'));
}
My full x.blade.php file:
#extends('layouts.app')
#section('slide_bar')
#include('layouts.master_entry_slide_bar')
#endsection
#section('content')
<section class="content-header">
<h1>BASL Ethnicity <small>page </small></h1>
</section>
<br/>
<!-- Main content -->
<section class="content-fluid">
<div class="row">
<div class="col-xs-12">
<div class="box">
<div class="box-body">
<table id="example1" class="table table-bordered table-striped">
<col width='auto'>
<col width='auto'>
<col width='100'>
<thead>
<tr>
<th>Member Ethnicity Code</th>
<th>Member Name</th>
<th><p id='buttons'> <strong> Add New Ethnicity &nbsp </strong> <span class="glyphicon glyphicon-plus"></span> </p></th>
</tr>
</thead>
<tbody>
#foreach ($ethenics as $ethenic)
<tr>
<td> {{ $ethenic->ethenicCode }} </td>
<td> {{ $ethenic->ethenicName }} </td>
<td align='center'>
{!! Form::open(['method' => 'DELETE', 'route'=>['ethenics.destroy',$ethenic->id]]) !!}
<span class="glyphicon glyphicon-pencil"></span> &nbsp &nbsp
<button type="submit" class="btn btn-default btn-sm" onclick="return confirm('Are you sure?')"> <span class="glyphicon glyphicon-trash"></span> </button>
{!! Form::close() !!}
</td>
</tr>
#endforeach
</tbody>
<tfoot>
<tr>
<th>Member Ethnicity Code</th>
<th>Member Name</th>
<th></th>
</tr>
</tfoot>
</table>
</div><!-- /.box-body -->
</div><!-- /.box -->
</div><!-- /.col -->
</div><!-- /.row -->
</section><!-- /.content -->
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="btn btn-default" style='float: right;' data-dismiss="modal"><span class="glyphicon glyphicon-remove-circle"></span></button>
</span>
</span>
<h4 class="modal-title">Member Ethnicity Details</h4>
</div>
<!-- text input -->
<div class="modal-body">
{!! Form::label('e_code', 'Ethnicity Code: '); !!}
{!! Form::text('ethenicity_code', null, ['class' => 'form-control', 'id' => 'ethenicity_code', 'placeholder' => 'Enter Ethnicity Code here','disabled' => 'disabled']); !!}
{!! Form::label('e_name', 'Ethnicity Name: '); !!}
{!! Form::text('ethenicity_name', null, ['class' => 'form-control', 'id' => 'ethenicity_name', 'placeholder' => 'Enter Ethnicity Name here' ,'disabled' => 'disabled']); !!}
</div>
</div>
</div>
</div>
<script>
var name = document.getElementById("master_entry");
document.getElementById("master_entry").className = "active";
var slide_bar_element = document.getElementById("ane_menu");
document.getElementById("ane_menu").className = "active";
var slide_bar_element = document.getElementById("ane_submenu3");
document.getElementById("ane_submenu3").className = "active";
</script>
#endsection

Related

Paginate one page with different tabs Laravel

I want to paginate in a blade file different tabs , each tabs show different collections of object but each time i go to next page in one page it redirects to the first tab and also paginate each tab not just the one i wanted to paginate.
Blade Part Where i have tabs
<div class="container">
<div class="section-bg-color">
<div class="row">
<div class="col-lg-12">
<!-- My Account Page Start -->
<div class="myaccount-page-wrapper">
<!-- My Account Tab Menu Start -->
<div class="row">
<div class="col-lg-3 col-md-4">
<div class="myaccount-tab-menu nav" role="tablist" id="myTab">
<i class="fa fa-dashboard"></i>Dashboard
<i class="fa fa-user"></i>Gestione Utenti
<i class="fa fa-book"></i>Gestione Fumetti
<i class="fa fa-map-marker"></i>Gestione Recensione
</div>
</div>
<!-- My Account Tab Menu End -->
<!-- My Account Tab Content Start -->
<div class="col-lg-9 col-md-8">
<div class="tab-content" id="myaccountContent">
<!-- Single Tab Content Start -->
<div class="tab-pane fade show active" id="dashboad" role="tabpanel">
<div class="myaccount-content">
<h5>Dashboard</h5>
<div class="welcome">
<p>Ciao, <strong>{{ $user->username }}</strong>! (Non sei <strong>{{ $user->username }}</strong>? Logout)</p>
</div>
<p class="mb-0">I tuoi dati:</p>
<p class="mb-0">E-mail: <strong>{{ $user->email }} </strong></p>
</div>
<div class="myaccount-content">
#php
$notifications = \App\Http\Controllers\NotificationController::getNotification($user->id);
#endphp
<h5>Notifiche</h5>
#if($notifications->count() < 1)
<div class="myaccount-content">
<h5>Non ci sono ancora notifiche</h5>
</div>
#else
<div class="myaccount-table table-responsive text-center">
<table class="table table-bordered">
<thead class="thead-light">
<tr>
<th>Data</th>
<th>testo</th>
<th>stato</th>
<th>Action</th>
</tr>
</thead>
<tbody>
#foreach($notifications as $notification)
<tr>
<td>{{ $notification->date }}</td>
<td>
#if(strlen($notification->notification_text) > 50 )
#php
$subnotification = substr($notification->notification_text, 0, 50)
#endphp
{{ $subnotification }}...
#else
{{ $notification->notification_text }}
#endif
</td>
#if($notification->state == 1)
<td>
Letto
</td>
<td>
View
</td>
#else
<td>
Non letto
</td>
<td>
View
</td>
#endif
</tr>
#endforeach
</tbody>
</table>
</div>
#endif
</div>
</div>
<!-- Single Tab Content End -->
#if(session('message'))
{{session('message')}}
#endif
<!-- Single Tab Content Start -->
<div class="tab-pane fade" id="users" role="tabpanel">
<div class="myaccount-content">
<h5>Utenti</h5>
<div class="myaccount-table table-responsive text-center">
<table class="table table-bordered">
<thead class="thead-light">
<tr>
<th>Nickname</th>
<th>Phone</th>
<th>Email</th>
<th>Tipologia</th>
<th>Elimina</th>
</tr>
</thead>
<tbody>
#foreach($users as $user)
<tr>
<td>{{$user->username}}</td>
<td>{{$user->phone_number}}</td>
<td>{{$user->email}}</td>
#if($user->hasGroup('il gruppo degli utenti'))
<td>Utente</td>
#else
<td>Venditore</td>
#endif
<td><a class="btn btn-danger" onclick="return myFunction();" href="{{route('user-delete', $user->id)}}"><i class="fa fa-trash"></i></a></td>
<script>
function myFunction() {
if(!confirm("Sei sicuro di voler eliminare questo utente"))
event.preventDefault();
}
</script>
</tr>
#endforeach
{{ $users->links() }}
</tbody>
</table>
</div>
</div>
</div>
<!-- Single Tab Content End -->
<!-- Single Tab Content Start -->
<div class="tab-pane fade" id="comics" role="tabpanel">
<div class="myaccount-content">
<h5>Fumetti</h5>
<div class="myaccount-table table-responsive text-center">
<table class="table table-bordered">
<thead class="thead-dark">
<tr>
<th>Titolo</th>
<th>ISBN</th>
<th>Quantità</th>
<th>Utente</th>
<th>Elimina</th>
</tr>
</thead>
<tbody>
#foreach($comics as $comic)
#php
$userNeed = App\User::where('id','=',$comic->user_id)->first();
#endphp
<tr>
<td>{{$comic->comic_name}}</td>
<td>{{$comic->ISBN}}</td>
<td>{{$comic->quantity}}</td>
<td>{{$userNeed->username}}</td>
<td><a class="btn btn-danger" onclick="return myFunction();" href="{{route('comic-delete', $comic->id)}}"><i class="fa fa-trash"></i></a></td>
<script>
function myFunction() {
if(!confirm("Sei sicuro di voler eliminare questo fumetto"))
event.preventDefault();
}
</script>
</tr>
#endforeach
{{ $comics->links() }}
</tbody>
</table>
</div>
</div>
</div>
<!-- Single Tab Content End -->
<!-- Single Tab Content Start -->
<div class="tab-pane fade" id="reviews" role="tabpanel">
<div class="myaccount-content">
<h5>Recensione</h5>
<div class="myaccount-table table-responsive text-center">
<table class="table table-bordered">
<thead class="thead-dark">
<tr>
<th>Titolo</th>
<th>Fumetto</th>
<th>Recensore</th>
<th>Elimina</th>
</tr>
</thead>
<tbody>
#foreach($reviews as $review)
#php
$userReview = App\User::where('id','=',$review->user_id)->first();
$comicReview = App\Comic::where('id','=',$review->comic_id)->first();
#endphp
<tr>
<td>{{$review->review_title}}</td>
<td>{{$comicReview->comic_name}}</td>
<td>{{$userReview->username}}</td>
<td><a class="btn btn-danger" onclick="return myFunction();" href="{{route('review-delete-local', $review->id)}}"><i class="fa fa-trash"></i></a></td>
<script>
function myFunction() {
if(!confirm("Sei sicuro di voler eliminare questa recensione"))
event.preventDefault();
}
</script>
</tr>
#endforeach
{{ $reviews->links() }}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div> <!-- My Account Tab Content End -->
</div>
</div> <!-- My Account Page End -->
</div>
</div>
</div>
</div>
</div>
And this is my route
Route
Route::get('/adminArea', function () {
$user = \Illuminate\Support\Facades\Auth::user();
$users = \App\User::where('username','!=','admin')->orderBy('username', 'asc')->paginate(12);
$comics =Comic::orderBy('comic_name', 'asc')->paginate(12);
$reviews = \App\Review::orderBy('review_title', 'asc')->paginate(12);
return view('adminPanel')
->with(compact('user'))
->with(compact('users'))
->with(compact('comics'))
->with(compact('reviews'));
})->name('AdminAccount');
In the end what i want to do is to paginate each tab differently meaning if a put the next on the comics i don't want to show also in the user tab the second page of user. The problem is that it use the same pagination url for each tabs so i was wondering if the solution is to give each tab an indipendent url
It redirects to the first tab because you use javascript tabs with active class added to first tab. To resolve problem with tabs you need to change for each tabs nav to:
<a href="#dashboad" class="{{ (Route::currentRouteName() == 'YOUR-ROUTE-NAME) ? 'active' : '' }}" ...
Also here:
<!-- Single Tab Content Start -->
<div class="tab-pane fade show {{ (Route::currentRouteName() == 'YOUR-ROUTE-NAME) ? 'active' : '' }}"...
But your problems with paginations will remain.
Here are 2 solutions:
Use JS tabs and get data via Ajax request.
Use 4 separated routes for each collection and add routes to tabs corresponding above example.
I hope it was clear.
Solution look like this.
Navigation code:
<div class="myaccount-tab-menu nav" role="tablist" id="myTab">
<i class="fa fa-dashboard"></i>Dashboard
<i class="fa fa-user"></i>Gestione Utenti
<i class="fa fa-book"></i>Gestione Fumetti
<i class="fa fa-map-marker"></i>Gestione Recensione
</div>
Also for each tab add, don't forget to change route name for each:
<!-- Single Tab Content Start -->
<div class="tab-pane fade show {{ (Route::currentRouteName() == 'dashboard') ? 'active' : '' }}" id="dashboad" role="tabpanel">
Route code:
Route::get('/dashboard', function () {
$user = \Illuminate\Support\Facades\Auth::user();
return view('adminPanel')->with(compact('user'));
})->name('dashboard');
Route::get('/users', function () {
$users = \App\User::where('username','!=','admin')->orderBy('username', 'asc')->paginate(12);
return view('adminPanel')->with(compact('users'));
})->name('users');
Route::get('/comics', function () {
$comics =Comic::orderBy('comic_name', 'asc')->paginate(12);
return view('adminPanel')->with(compact('comics'));
})->name('comics');
Route::get('/reviews', function () {
$reviews = \App\Review::orderBy('review_title', 'asc')->paginate(12);
return view('adminPanel')->with(compact('reviews'));
})->name('reviews');

CRUD - Delete on Laravel

I am stuck on my button "delete" when I try to delete a recording nothing happens.
In my StudentController I have that:
public function destroy($id)
{
$student = Student::find($id);
$student->delete();
return redirect()->route('student.index')
->with('success', 'Deleted successfully');
}
And in my index.blade.php I have that:
#section('content')
<div class="px-content">
<div class="page-header">
<div class="row">
<div class="col-md-4 text-xs-center text-md-left text-nowrap">
<h1><i class="px-nav-icon ion-android-apps"></i>List </h1>
</div>
<hr class="page-wide-block visible-xs visible-sm">
<!-- Spacer -->
<div class="m-b-2 visible-xs visible-sm clearfix"></div>
</div>
</div>
<div class="row">
<div class="panel">
<div class="panel-body">
<div class="table-responsive">
<table class="table">
<a class="btn btn-sm btn-success" href="{{ route('student.create') }}">Create</a>
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
</thead>
#foreach($students as $student)
<tr>
<td> {{$student->firstname}}</td>
<td> {{$student->lastname}} </td>
<td>
<a class="btn btn-sm btn-warning" href="{{route('student.edit',$student->id)}}">Edit</a>
#csrf
#method('DELETE')
<button type="submit" class="btn btn-sm btn-danger">Delete</button>
</td>
</tr>
#endforeach
</table>
</div>
</div>
</div>
</div>
{!! $students->links() !!}
</div>
#endsection
For the folder route
Auth::routes();
route::resource('student','AdminController');
Route::PATCH('/update/{id}','AdminController#update');
I don't understand where is the problem ? I would like to know my error because I don't have of error message in fact.
Thank you in advance.
You are missing the form so surround your button with a form tag like this:
<form method="POST" action="{{ route('student.destroy', $student) }} ">
#csrf
#method('DELETE')
<button type="submit" class="btn btn-sm btn-danger">Delete</button>
</form>

Partial Print Area PHP

I'm kinda new here, just need help with small code.
I need to print specific area with a Print Payment Record that I've already added, I've added a new button, tried with another tutorial but I couldn't do it, with my other code print the entire page.
I know I can highlight the table and hit print but having a button is easier mostly when the record is like 50 payments.
Start in Deposit Fee in Details.
Help with these please!
This is my code:
#extends('branch.layout.main')
#section('title') Manage Fee #endsection
#section('content')
<div class="container">
<div class="section">
#section('button')
Deposit Fee
#endsection
<div class="row">
<div class="col s12 m12 l12">
<div class="card-panel">
<div class="row">
<h4 class="header2" style="color:#00bcd4"><i class="mdi-social-person" style="font-size:20px"></i> Fee Detail of {{ $student->first_name." ".$student->last_name }}</h4>
<table class="striped" >
<thead>
<tr>
<th>Current Course</th>
<th>Course Fee</th>
<th>Discount</th>
<th>Any Extra</th>
<th>Total Payable</th>
<th>Deposited Fee</th>
<th>Balance</th>
</tr>
<tr>
<td width="20%">{{ $course->courseName }}</td>
<td width="13%">{{ IMS::currency().$course->course_fee }}</td>
<td width="13%">{{ IMS::currency().$course->discount }}</td>
<td width="13%">{{ IMS::currency().$extra }}</td>
<td width="13%">{{ IMS::currency().$payable }}</td>
<td width="13%">{{ IMS::currency().$deposited }}</td>
<td width="13%"><span style="color:red">{{ IMS::currency().$balance }}</span></td>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
</div>
<!--Deposited Fee in Detail-->
#if(count($fees) > 0)
<div class="row">
<div class="col s12 m12 l12">
<div class="card-panel">
<div class="row">
<h4 class="header2" style="color:#00bcd4"><i class="mdi-content-add" style="font-size:20px"></i> Deposited Fee of {{ $student->first_name." ".$student->last_name }}</h4>
<button onclick="printContent('row')">Print Payment Record </button>
<table class="striped" >
<thead>
<tr>
<th>Date Added</th>
<th>Amount</th>
<th>Course</th>
<th>Due Date</th>
<th>Option</th>
</tr>
#foreach($fees as $fee)
<tr>
<td width="20%">{{ date('d-M-Y',strtotime($fee->date_added)) }}</td>
<td width="20%">{{ IMS::currency().$fee->amount }}</td>
<td width="20%">{{ $fee->courseName }}</td>
<td width="20%">#if($fee->due_date) {{ date('d-M-Y',strtotime($fee->due_date)) }} #else --- #endif</td>
<td width="20%">
<i class="mdi-maps-local-print-shop"></i>
<i class="mdi-maps-local-print-shop"></i>
#if($delete)
<i class="mdi-content-clear"></i>
#endif
</td>
</tr>
#endforeach
</thead>
</table>
</div>
</div>
</div>
</div>
</div>
#endif
<!--End Deposited Fee in Detail-->
<!--Add New Fee-->
<div id="AddNew" class="modal modal-fixed-footer">
<div class="modal-content">
<h4 class="header2">Deposit Fee For {{ $student->first_name }} {{ $student->last_name }}</h4>
<form action="{{ Asset('fee/'.$student->id) }}" method="post">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="row">
<div class="input-field col s6">
<i class="mdi-editor-insert-invitation prefix"></i>
{!! Form::date('date_added',date('Y-m-d'),['id' => 'date_added','class' => 'datepicker']) !!}
<label for="date_added">Date Added *</label>
</div>
<div class="input-field col s6">
<i class="mdi-editor-attach-money prefix"></i>
{!! Form::number('amount',null,['id' => 'amount','required' => 'required','pattern' => '[0-9]{10}']) !!}
<label for="amount">Amount *</label>
</div>
</div>
<div class="row">
<div class="input-field col s6">
<select name="payment_mode">
<option>Please select Payment Type</option>
<option>Cash</option>
<option>Cheque</option>
<option>Card</option>
<option>Credit or Discount</option>
</select>
</div>
<div class="input-field col s6">
{!! Form::text('cheque_Card_Number', null, ['id' => 'cheque_Card_Number']) !!}
</div>
</div>
<p style="color:red"><i class="fa fa-bell"></i> If you want fee due reminder then select fee due date,if not then leave empty</p>
<div class="row">
<div class="input-field col s12">
<i class="mdi-editor-insert-invitation prefix"></i>
{!! Form::date('due_date',null,['id' => 'due_date','class' => 'datepicker']) !!}
<label for="due_date">Due Date</label>
</div>
</div>
<div class="modal-footer">
Close
<button type="submit" class="btn blue modal-action modal-close">Save</button>
</div>
</form>
</div>
</div>
<!--End Add New Fee-->
#endsection

Laravel : Search result search?page=2 show nothing, just blank page

My pagination works correctly, but when use search component it display only first page of result.
My page URL without search looks like:
http://localhost:8000/dictionary-management/postcode?page=2
And it's work correctly.
My first page URL with search:
http://localhost:8000/dictionary-management/postcode/search
and it's work correctly.
My second page URL with search:
http://localhost:8000/dictionary-management/postcode/search?page=2
and the is nothing to show, only blank page.
This is my Controller Search method:
public function search(Request $request) {
$constraints = [
'postcode' => $request['postcode'],
'address' => $request['address']
];
$postcodes = $this->doSearchingQuery($constraints);
return view('dictionary-mgmt/postcode/index', ['postcodes' => $postcodes, 'searchingVals' => $constraints]);
}
private function doSearchingQuery($constraints) {
$query = Postcode::query();
$fields = array_keys($constraints);
$index = 0;
foreach ($constraints as $constraint) {
if ($constraint != null) {
$query = $query->where( $fields[$index], 'like', '%'.$constraint.'%');
}
$index++;
}
return $query->Paginate(5);
}
This is my route :
Route::resource('dictionary-management/postcode', 'PostCodeController');
Route::post('dictionary-management/postcode/search', PosstCodeController#search')->name('postcode.search');
This is my index view :
#extends('dictionary-mgmt.postcode.base')
#section('action-content')
<!-- Main content -->
<section class="content">
<div class="box">
<div class="box-header">
<div class="row">
<div class="col-sm-8">
<h3 class="box-title">List kodów pocztowych</h3>
</div>
<div class="col-sm-4">
<a class="btn btn-primary pull-right" href="{{ route('postcode.create') }}">Dodaj nowy kod pocztowy</a>
</div>
</div>
</div>
<!-- /.box-header -->
<div class="box-body">
<div class="row">
<div class="col-sm-6"></div>
<div class="col-sm-6"></div>
</div>
<form method="POST" action="{{ route('postcode.search') }}">
{{ csrf_field() }}
#component('layouts.search', ['title' => 'Szukaj'])
#component('layouts.two-cols-search-row', ['items' => ['postcode', 'address'], 'title' => ['Kod','Adres'],
'oldVals' => [isset($searchingVals) ? $searchingVals['postcode'] : '', isset($searchingVals) ? $searchingVals['address'] : '']])
#endcomponent
#endcomponent
</form>
<div id="example2_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
<div class="row">
<div class="col-sm-12">
<table id="example2" class="table table-bordered table-hover dataTable" role="grid" aria-describedby="example2_info">
<thead>
<tr role="row">
<th width="5%">Kod pocztowy</th>
<th width="40%">Adres</th>
<th width="10%">Miejscowość</th>
<th width="10%">Województwo</th>
<th width="10%">Powiat</th>
<th>Akcja</th>
</tr>
</thead>
<tbody>
#foreach ($postcodes as $postcode)
<tr role="row" class="odd">
<td>{{ $postcode->postcode }}</td>
<td>{{ $postcode->address }}</td>
<td>{{ $postcode->city }}</td>
<td>{{ $postcode->voivodeship }}</td>
<td>{{ $postcode->county }}</td>
<td>
<form class="row" method="POST" action="{{ route('postcode.destroy', ['id' => $postcode->id]) }}" onsubmit = "return confirm('Czy napewno usunąć?')">
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<a href="{{ route('postcode.edit', ['id' => $postcode->id]) }}" class="btn btn-warning col-sm-3 col-xs-5 btn-margin">
Edytuj
</a>
<button type="submit" class="btn btn-danger col-sm-3 col-xs-5 btn-margin">
Usuń
</button>
</form>
</td>
</tr>
#endforeach
</tbody>
<tfoot>
<tr>
<th width="5%">Kod pocztowy</th>
<th width="40%">Adres</th>
<th width="10%">Miejscowość</th>
<th width="10%">Województwo</th>
<th width="10%">Powiat</th>
<th>Akcja</th>
</tr>
</tfoot>
</table>
</div>
</div>
<div class="row">
<div class="col-sm-5">
</div>
<div class="col-sm-7">
<div class="dataTables_paginate paging_simple_numbers" id="example2_paginate">
{{ $postcodes->links() }}
</div>
</div>
</div>
</div>
</div>
<!-- /.box-body -->
</div>
</section>
<!-- /.content -->
</div>
#endsection
And this is my search component:
<div class="row">
#php
$index = 0;
#endphp
#foreach ($items as $item)
<div class="col-md-6">
<div class="form-group">
#php
$stringFormat = strtolower(str_replace(' ', '', $item));
#endphp
<label for="input<?=$stringFormat?>" class="col-sm-3 control-label">{{$title[$index]}}</label>
<div class="col-sm-9">
<input value="{{isset($oldVals) ? $oldVals[$index] : ''}}" type="text" class="form-control" name="<?=$stringFormat?>" id="input<?=$stringFormat?>" placeholder="{{$title[$index]}}">
</div>
</div>
</div>
#php
$index++;
#endphp
#endforeach
</div>
Please help, I don't know where is my mistake...
Try this
{{ $postcodes->appends(request()->input())->links()}}
instead of {{ $postcodes->links() }}

Using typeahead.js with laravel

I'm trying t use twitter typeahead.js with laravel, but it does not work. Here's my code
create.blade.php
<!-- app/views/nerds/create.blade.php -->
<!DOCTYPE html>
<html>
<head>
<title>Crear Detalle</title>
<link rel="stylesheet" href="{{ asset('css/bootstrap.min.css') }}">
<link rel="stylesheet" type="text/css" href="{{ URL::asset('css/main.css') }}" />
<script type="text/javascript" src="{{ URL::asset('js/jquery-2.1.1.min.js') }}" ></script>
<script type="text/javascript" src="{{ URL::asset('js/bootstrap.min.js') }}" ></script>
<script type="text/javascript" src="{{ URL::asset('js/typeahead.js') }}" ></script>
</head>
<script>
$(document).ready(function()
{
$.ajax({
type: "POST",
url: "http://chapincar.dev/notas_detalle/create",
data: "autocomplete="+$("input[name=autocomplete]").val(),
success: function(data)
{
json = $.parseJSON(data);//parseamos el json
var codigo = json
console.log(codigo)
$('#remote .typeahead').typeahead({
minLength: 3,
highlight: true,
},
{
name: 'codigo',
source: codigo
});
},
error: function(data)
{
json = $.parseJSON(data);//parseamos el json
var error = json
console.log(error)
}
});
});
</script>
<body>
<div class="container">
<nav class="navbar navbar-inverse">
<div class="navbar-header">
<a class="navbar-brand" href="{{ URL::to('nota_detalle') }}">Panel de Detalles de Ordenes</a>
</div>
<ul class="nav navbar-nav">
<li>Ver todos los Detalles</li>
<li>Crear un Detalle
</ul>
</nav>
<h1>Crear Detalle</h1>
<!-- if there are creation errors, they will show here -->
{{ HTML::ul($errors->all() )}}
{{ Form::open(array('url' => 'nota_detalle', 'class' => '')) }}
<table>
<tr>
<td class="ancho">
<div class="form-group">
{{ Form::label('codigo_nota', 'Codigo Orden') }}
{{ Form::text('codigo_nota', Input::old('codigo_nota'), array('class' => 'form-control')) }}
</div>
</td>
<td class="ancho">
<a href="#" class="btn btn-default"
data-toggle="modal"
data-target="#modalCliente">Buscar</a>
</td>
</tr>
<tr>
<td class="ancho">
<div class="form-group">
{{ Form::label('cantidad_detalle', 'Cantidad') }}
{{ Form::text('cantidad_detalle', Input::old('cantidad_detalle'), array('class' => 'form-control')) }}
</div>
</td>
</tr>
<tr>
<td class="ancho">
<div class="form-group">
{{ Form::label('descripcion_detalle', 'Descripción') }}
{{ Form::textarea('descripcion_detalle', Input::old('descripcion_detalle'), array('class' => 'form-control')) }}
</div>
</td>
</tr>
<tr>
<td class="ancho">
<div class="form-group">
{{ Form::label('precioIVA_detalle', 'Precio con IVA') }}
{{ Form::number('precioIVA_detalle', Input::old('precioIVA_detalle'), array('class' => 'form-control')) }}
</div>
</td>
</tr>
<tr>
<td class="ancho">
<div class="form-group">
{{ Form::label('precioSinIVA_detalle', 'Precio sin IVA') }}
{{ Form::number('precioSinIVA_detalle', null, array('class' => 'form-control', 'size' => '30x4')) }}
</div>
</td>
</tr>
<tr>
<td class="ancho">
<div class="form-group">
{{ Form::label('precioTotal_detalle', 'Precio Total') }}
{{ Form::number('precioTotal_detalle', null, array('class' => 'form-control')) }}
</div>
</td>
</tr>
</table>
{{ Form::submit('Agregar Detalle!', array('class' => 'btn btn-primary')) }}
{{ Form::close() }}
<!-- Modal -->
<div class="modal fade" id="modalCliente" tabindex="-1" role="dialog" aria-labelledby="basicModal" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<div class="form-group remote">
<label for="query">Search:</label>
<input class="form-control" name="autocomplete" id="autocomplete" placeholder="Start typing something to search..." type="text">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" aria-hidden="true">Cerrar</button>
</div>
</div>
</div>
</div>
{{Form::close()}}
</div>
</body>
</html
>
This is my routes.php file
Route::post("nota_detalle/create", function(){
$search = Input::get("autocomplete");
$query = DB::table("notas_cabecera")->where('chapa_vehiculo', 'LIKE', '%'.$search.'%')->get(['codigo_nota']);
Response::json($query);
});
These are my error logs:
This is my database:
https://www.dropbox.com/s/1li3hhylw7ukbv0/Imagen%202.png?dl=0
Can you help me please
So as per #Loz Cherone's comment on the server side i nyour laravel router the paramater is query.
The other thing is your manually using echo json_encode, dont use this use a built in laravel function return Response::json($query); its a bit cleaner and you dont want to use echo in your routes file.
More info on laravel responses - http://laravel.com/docs/4.2/responses#special-responses
if your having more issues check the console on your browser to help give us more details.

Categories