when ever I delete a user from my records the wrong user gets deleted
the deletion is happening in an incremented way no matter what the user id I'm choosing to delete
let's say I'm deleting the user with the id 4
the one that actually gets deleted is the one with the id 1
if I try again to delete id 4 the user with the id of 2 gets deleted and so on.
my view is :
#extends('layouts.app')
#section('content')
<!-- Content Header (Page header) -->
<div class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="m-0">{{ __('Admin panel') }}</h1>
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.container-fluid -->
</div>
<!-- /.content-header -->
<!-- Main content -->
<div class="content">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<h5 class="card-title"></h5>
<p class="card-text">
#if (Session::has('successMsg'))
<div class="alert alert-success">
<h6 style=" text-align:center !important;"><b>Successfully Deleted! </b></h6>
</div>
#endif
<a class="btn btn-primary m-2" href="/addAppointment">Add new Appointment</a>
Appointments List
<div class="container">
#if ($users->count())
<table class="table" id="table">
<thead>
<tr>
<th>Id</th>
<th>Email</th>
<th>View</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
#foreach ($users as $user)
#if ($user->id > 1)
<tr>
<td>{{ $user->id }}</td>
<td>{{ $user->email }}</td>
<td><a href="/cpanel/{{ $user->id }}"
class="btn">👁</a></td>
<td>
<form action="/cpanel/{{ $user->id }}" method="POST"
id="EditForm">
#method('DELETE')
#csrf
<button type="submit" class="btn" data-toggle="tooltip"
title='Delete' onclick="submitResult(event)"
aria-hidden="true">🗑</button>
</form>
</td>
</tr>
#endif
#endforeach
</tbody>
</table>
#endif
</div>
</p>
</div>
</div>
</div>
</div>
<!-- /.row -->
</div><!-- /.container-fluid -->
</div>
<!-- /.content -->
#endsection
#section('scripts')
<script src="//cdn.jsdelivr.net/npm/sweetalert2#11"></script>
<script src="sweetalert2.all.min.js"></script>
<script type="text/javascript">
function submitResult(e) {
e.preventDefault();
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.isConfirmed) {
Swal.fire(
'Deleted!',
'Your file has been deleted.',
'success'
)
document.getElementById("EditForm").submit();
}
})
}
</script>
<script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script type="text/javascript" language="javascript"
src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.min.js"></script>
#endsection
#section('styles')
<link href='https://cdn.jsdelivr.net/npm/sweetalert2#10.10.1/dist/sweetalert2.min.css'>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.2/dist/css/bootstrap.min.css"
integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.12.1/css/jquery.dataTables.min.css">
#endsection
my destroy function in the user controller is:
public function destroy($id)
{
if (!Auth::check()) {
return redirect('login');
} elseif (Gate::denies('cpanel')) {
abort(403, 'action not allowed!');
} else {
User::destroy($id);
return redirect('cpanel')->with('successMsg', 'User Deleted !');
}
}
my route is:
Route::resource('/cpanel', UserController::class)->middleware(['auth', 'verified']);
what Am I missing?
EDIT:
it seems that the onclick="submitResult(event)"
is causing some problem, when I remove the onclick event
the id gets sent correctly to the destroy function.
can you please Help fix this.
i think this was probably an error caused by me.
the problem is fixed after I changed the
onclick="submitResult(event)"
to
onclick="submitResult(e)"
the id is now being sent correctly to the destroy function.
problem fixed.
Related
I have this issue:
Illuminate\Routing\Exceptions\UrlGenerationException
Missing required parameter for [Route: admin.percent.edit] [URI: {locale}/admin/percent/edit/{id}] [Missing parameter: id]. (View: C:\Users\kawed\OneDrive\Desktop\flooss\resources\views\admin\includes\top.blade.php)
index page code:
#extends('admin.layouts.app')
#section('headSection')
<!-- form Uploads -->
<link href="{{ asset('back/assets/plugins/datatable/dataTables.bootstrap4.min.css') }}" rel="stylesheet" type="text/css" />
#endsection
#section('content')
<div class="page-header mt-0 shadow p-3">
<ol class="breadcrumb mb-sm-0">
<li class="breadcrumb-item">
{{ __('val.home') }}
</li>
<li class="breadcrumb-item active" aria-current="page">
{{ __('val.dashboard_percent') }}
</li>
</ol>
<a href="/{{ app()->getLocale() }}/admin/percent/create">
<button type="button" class="btn btn-success btn-pill mt-1 mb-1">{{ __('val.create_percent') }}</button>
</a>
</div>
<div class="row">
<div class="col-md-12">
<div class="card shadow">
<div class="card-header">
<h2 class="mb-0">Data Table</h2>
</div>
<div class="card-body">
<div class="table-responsive">
<table id="example" class="table table-striped table-bordered w-100 text-nowrap">
<thead>
<tr>
<th class="wd-15p">id</th>
<th class="wd-15p">{{ __('session.percent') }}</th>
<th class="wd-20p">{{ __('session.edit') }}</th>
<th class="wd-15p">{{ __('session.delete') }}</th>
</tr>
</thead>
<tbody>
#foreach($percents as $item)
<tr>
<td>
{{ $item->id }}
</td>
<td>
{{ $item->pname }}
</td>
<td>
{{ __('session.edit') }}
</td>
<td>
{{ __('session.delete') }}
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
#endsection
#section('footerSection')
<!-- file uploads js -->
<script src="{{ asset('back/assets/plugins/datatable/jquery.dataTables.min.js') }}"></script>
<script src="{{ asset('back/assets/plugins/datatable/dataTables.bootstrap4.min.js') }}"></script>
<script>
$(function(e) {
$('#example').DataTable();
var table = $('#example1').DataTable();
$('button').click(function() {
var data = table.$('input, select').serialize();
alert(
"The following data would have been submitted to the server: \n\n" +
data.substr(0, 120) + '...'
);
return false;
});
$('#example2').DataTable({
"scrollY": "200px",
"scrollCollapse": true,
"paging": false
});
});
</script>
#endsection
Edited page code:
#extends('admin.layouts.app')
#section('headSection')
<!-- form Uploads -->
<link href="{{ asset('back/assets/plugins/fileuploads/css/dropify.css') }}" rel="stylesheet" type="text/css" />
#endsection
#section('content')
<div class="page-header mt-0 shadow p-3">
<ol class="breadcrumb mb-sm-0">
<li class="breadcrumb-item">
{{ __('val.home') }}
</li>
<li class="breadcrumb-item active" aria-current="page">
{{ __('val.dashboard_percent') }}
</li>
</ol>
</div>
<div class="row">
<div class="col-md-12">
<form action="{{ route('admin.percent.edit', ['id' => $category->id, 'locale' => app()->getLocale()]) }}" method ="post" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="card shadow">
<div class="card-header">
<h2 class="mb-0">{{ __('val.edit_percent') }}</h2>
#include('admin.includes.messages')
</div>
<div class="card-body">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" name="categoryarabicname" value="{{ $category->categoryarabicname }}">
</div>
<div class="form-group">
<input type="text" class="form-control" name="categoryengname" value="{{ $category->categoryengname }}">
</div>
<div class="form-group">
<textarea class="form-control"name="categoryarabicdesc" id="exampleFormControlTextarea1" rows="3">{{ $category->categoryarabicdesc }}</textarea>
</div>
<div class="form-group">
<textarea class="form-control"name="categoryengdesc" id="exampleFormControlTextarea1" rows="3">{{ $category->categoryengdesc }}</textarea>
</div>
</div>
<div class="col-md-6">
<div class="card shadow">
<div class="card-header">
<h2 class="mb-0">Upload Image</h2>
</div>
<div class="card-body">
<input type="file" name="catimage" class="dropify" data-height="300" />
</div>
<input type="hidden" name="image2" class="form-control" id="exampleInputEmail1">
</div>
<div class="card shadow overflow-hidden">
<img alt="Image placeholder" width=250px height=250px class="big" src="/uploads/{{ $category->categoryimage }}">
</div>
</div>
<div class="col-lg-9"></div>
<div class="col-lg-3">
<button type="submit" class="btn btn-success btn-square mt-1 mb-1">Update</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
#endsection
#section('footerSection')
<!-- file uploads js -->
<script src="{{ asset('back/assets/plugins/fileuploads/js/dropify.min.js') }}"></script>
<script>
$('.dropify').dropify({
messages: {
'default': 'Drag and drop a file here or click',
'replace': 'Drag and drop or click to replace',
'remove': 'Remove',
'error': 'Ooops, something wrong appended.'
},
error: {
'fileSize': 'The file size is too big (2M max).'
}
});
</script>
#endsection
Controller code:
namespace App\Http\Controllers;
use App\Http\Requests\PercentEditRequest;
use App\Http\Requests\PercentRequest;
use App\Models\Percent;
use Illuminate\Http\Request;
class PercentController extends Controller
{
public function index()
{
$percents = Percent::orderBy('created_at', 'desc')->get();
return view('admin.percent.index', compact('percents'));
}
public function create()
{
return view('admin.percent.create');
}
public function store(PercentRequest $request)
{
$validated = $request->validated();
$category = new Percent();
$category->pname = strip_tags($request->pname);
$category->save();
return redirect()->route('admin.percent', ['locale' => app()->getLocale()])
->with('success', trans('session.success'));
}
public function edit(Request $request, $id) {
$id = $request->id;
$locale = $request->locale;
$category = Percent::find($id);
return view('admin/percent/edit', compact('category'));
}
public function update(PercentEditRequest $request, $id) {
$validated = $request->validated();
$category = Percent::find($id);
$category->categoryengname = strip_tags($request->categoryengname);
$category->categoryarabicname = strip_tags($request->categoryarabicname);
$category->categoryengdesc = strip_tags($request->categoryengdesc);
$category->categoryarabicdesc = strip_tags($request->categoryarabicdesc);
if (!empty($request->hasFile('catimage'))) {
$imagePath = $request->file('catimage');
$imageName = time() . '.' . $imagePath->getClientOriginalExtension();
$imagePath->move('uploads', $imageName);
$category->categoryimage= $imageName;
}
$category->save();
return redirect('/admin/percent')->with('success', 'percent Updated Successfuly');
}
public function destroy($id)
{
$category = Percent::find($id);
$category->delete();
return redirect('/admin/percent')->with('success','percent Deleted Successfuly');
}
}
you have 2 parameters in url as define (locale & id)
but in your function have only one id so add locale parameter
public function edit(Request $request, $locale, $id) {
or remove parameter from url and use it from request
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');
I have create a searsh view and i can go to the values in another page and it's working fine , I can see my values but when I have added pagination it's working again but when I press button number 2 of paination it's not working and it give me an error :
MethodNotAllowedHttpException in RouteCollection.php line 251
at RouteCollection->methodNotAllowed(array('POST')) ...
My functions:
public function searsh()
{
return view('resultats.recherche');
}
public function show(Request $request)
{
$this->validate($request, [
'cne' => 'required|integer',
]);
$exams = Exam::where('cne', $request->cne)->paginate(4);
return view('resultats.index', compact('exams'));
}
and this is my routes:
The first one that make me send a searsh request in db
Route::get('/chercher', 'ExamsController#searsh')->name('display-cne-search');
Route::post('/resultat', 'ExamsController#show')->name('show-exams-cne-results');
and this is my view
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
<style>
body{
background-repeat:no-repeat;
-webkit-background-size:cover;
-moz-background-size:cover;
-o-background-size:cover;
background-size:cover;
background-position:center;
background: url('image/t10.jpg');
}
.bling{
background:url('image/background.jpg');
}
</style>
#extends('layouts.master')
#section('content')
#if($exams->isEmpty())
<div style="width:100%;height:100px;background-color:white">
<center>
<p style="margin-top:50px;">Le cne que vous avez choisi est incorrecte entrer un autre cne svp <a href="/chercher">
<br>
<button style="margin-top:5px"class="btn btn-primary">Par ici</button></a>
</p>
</center>
</div>
#else
<div class="container">
<div class="row">
<center><div class="col-md-12">
<div style="border-radius:5px;background:url('image/background.jpg')">
<center>
<h2 style="color:white;font-weight: bold;padding-top:5px;padding-bottom:5px;" > Historique des résultats de l'étudiant(e) {{$prenom}} {{$nom}} <br>
CNE {{$cne}}</h2>
</center>
</div>
<center><table style="background-color:white;border-radius:5px;" class="table">
<head>
<tr>
<th>Matiére</th>
<th>Note</th>
<th>Semestre</th>
<th>Session</th>
<th>Année</th>
<th>Le prof vous a peut-être laissé une remarque</th>
<th>Demande Vérification</th>
</tr>
</head>
<body>
#foreach($exams as $exam)
<tr class="{{$loop->index % 2==0 ? 'bling' : ''}}">
<td>{{ $exam->matiere}}</td>
<td>{{ $exam->note}}</td>
<td>{{ $exam->sem}}</td>
<td>{{ $exam->ses}}</td>
<td>{{ $exam->an}}</td>
<td>
<center>
<button type="button" value="{{$exam->remarque}}" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter" onClick="document.getElementById('remarque').innerHTML=this.value">
Remarque
</button>
</center>
</td>
<td>
#if(!$exam->verification)
<button class="btn btn-succees" onclick="document.getElementById('verification-form-{{$exam->id}}').submit();" >
Vérifier la note
</button>
<form id="verification-form-{{ $exam->id }}" action="{{ route('display-num-search', $exam ) }}" method="post">
{{ csrf_field() }}
</form>
#elseif($exam->verification->etat=="En attente")
<center> <a title="{{$exam->verification->etat}}" style="background-color:orange" class="btn-floating btn pulse"></a></center></p>
#else
<center><p> Verifié <i title="Note verifié par le professeur" class="fas fa-user-check"></i></p></center>
#endif
</td>
</tr>
#endforeach
<center>{{ $exams->links()}}</center>
</body>
</table></center>
<!-- modal remarque -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Remarque du prof</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div style="font-size:15px;font-weight: bold;" id="remarque"></div>
</div>
</div>
</div>
</div>
</div></center>
</div>
</div>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous">
document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('.dropdown-trigger');
var instances = M.Dropdown.init(elems, options);
});
// Or with jQuery
$('.dropdown-trigger').dropdown();
</script>
#endif
#endsection
POST requires a CSRF token everytime to process the request.
So, for performing a search and getting the pagination you can set the route as:
Route::any('/resultat', 'ExamsController#show')->name('show-exams-cne-results');
By this method, the first search performed is handled with POST method with the CSRF token and later for paginations, GET method is used.
EDIT: To make searches:
Change your route to GET.
Route::get('/resultat', 'ExamsController#show')->name('show-exams-cne-results');
Also, change the form method to GET
<form id="verification-form-{{ $exam->id }}" action="{{ route('display-num-search', $exam ) }}" method="GET">
#extends('main')
#foreach ($hotel as $hotel)
#foreach ($city as $city)
#section('title'," $hotel->hotel - $city->city")
#endsection
#section('content')
{{-- Header --}}
<div style="background-image:url('../img/{{ $hotel->id }}.jpg'); height:400px; background-size:cover;">
<div class="container">
#include('partials._nav')
<div class="row">
<center>
<h2>
<div class="col-md-12 hotel-name">
{{ $hotel->hotel }}
<p class="city">
</h2>
{{ $city->city }}
#endforeach
</p>
</div>
</center>
</div>
</div>
{{-- End Search bar --}}
</div>
</div>
{{-- Header End here --}}
</div>
</div>
</div>
{{-- Modal Closed --}}
<div class="container">
{{-- Tab Start here --}}
<div class="tabs">
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">Overview</li>
<li role="presentation">Menu</li>
<li role="presentation">Comments <span class="disqus-comment-count" data-disqus-identifier="article_1_identifier"></span></li>
<li role="presentation">Photo</li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="home">
<div class="row">
<div class="col-md-3">
<h3>Contact No.</h3>
<p class="contactno">{{ $hotel->contactno }}</p>
<p class="remark">{{ $hotel->remark }}</p>
<h3>Cuisines</h3>
<p class="cuisines">{{ $hotel->cuisines }}</p>
<h3>Cost</h3>
<p class="cost">{{ $hotel->cost }}</p>
</div>
<div class="col-md-3">
<h3>Opening Hours</h3>
<p class="hours">{{ date('h:ia', strtotime($hotel->openfrom)) }} - {{ date('h:ia', strtotime($hotel->opento)) }}</p>
<h3>Address</h3>
<p class="address">{{ $hotel->address }}</p>
<div id="map" style="width:150px;height:100px;"></div>
</div>
<div class="col-md-3">
<h3>Highlights</h3>
<p class="highlight">{{ $hotel->highlight }}</p>
<h3>Featured in Collection</h3>
<p class="featured">{{ $hotel->featured }}</p>
</div>
</div>
</div>
<div role="tabpanel" class="tab-pane" id="profile">
<table class="table">
<tr>
<th>#</th>
<th>Dish</th>
<th>Price</th>
</tr>
#foreach ($menu as $menu)
<tr>
<td>{{ $menu->id }}</td>
<td>{{ $menu->dish_name }}</td>
<td>{{ $menu->price }}</td>
</tr>
#endforeach
</table>
</div>
<div role="tabpanel" class="tab-pane" id="messages">
{{-- Disqus Start from here --}}
<div id="disqus_thread"></div>
<script>
/**
* RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
* LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables*/
/*
var disqus_config = function () {
this.page.url = PAGE_URL; // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
};
*/
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = '//gobumpr.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the comments powered by Disqus.</noscript>
</div>
{{-- Disqus End Here --}}
<div role="tabpanel" class="tab-pane" id="settings"></div>
</div>
</div>
{{-- Tab End Here --}}
</div>
#endsection
#section('javascript')
<script>
function myMap() {
var mapCanvas = document.getElementById("map");
var mapOptions = {
center: new google.maps.LatLng({{ $hotel->directions }}),
zoom: 10
}
var map = new google.maps.Map(mapCanvas, mapOptions);
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?callback=myMap"></script>
<script id="dsq-count-scr" src="//gobumpr.disqus.com/count.js" async></script>
#endforeach
{{-- <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDu9JV__AvYU6auWV-QsJuV82TnLtrytm0&callback=initMap" async defer></script> --}}
#endsection
I am getting this:
Error::
ErrorException in Factory.php line 587:
Cannot end a section without first starting one. (View: E:\Other\gobumpr\resources\views\pages\select.blade.php)
In here
#section('title'," $hotel->hotel - $city->city")
#endsection
you don't gonna need an #endsection since you supply the content for the title.
The 2nd argument of #section() consider as the content for the #section()
Simply use #section('title'," $hotel->hotel - $city->city")
If you use #section('section_name', 'section_content') syntax, your section's content is "section_content". There is no need to close such section with #endsection.
Check https://laravel.com/docs/5.3/blade#extending-a-layout
#section('javascript')
function myMap() {
var mapCanvas = document.getElementById("map");
var mapOptions = {
center: new google.maps.LatLng({{ $hotel->directions }}),
zoom: 10
}
var map = new google.maps.Map(mapCanvas, mapOptions);
}
#endforeach
{{-- --}}
#endsection
The #endsection needs to be before the #endforeach.
removing #endsection will solve the problem. I'm trying to add title page with #yield('title') in <title></title> and provide with #section('title', 'pageTitle') without #endsection.
you defenetly forget the'#' before the word section
try to delete the #endsection after the section('title') it will fix it.
use #stop or #endsection (only one) in a blade template not both.
You should use #stop or #endsection after #section
For example
It'll work
#section('testing')
<h1>kjfdgjkfdgfd kjgkdfhgdljkfs hgdfhgjk</h1>
#endsection
It'll not work
#section('testing')
<h1>kjfdgjkfdgfd kjgkdfhgdljkfs hgdfhgjk</h1>
#endsection
#stop
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">×</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.