I am using the button to display the details of the particular person using the data-toggle="modal" but the button is not performing any action. When I click the button I am not able to display any details of the user.
Route:
Route::get('document', 'PatientController#show');
Controller:
public function show()
{
$patient_user=patient_user::all();
return view('document')->with('patient_user',$patient_user);
}
View:
<form id="myForm" method="get">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="panel-body">
<table class="table table-striped table-bordered table-hover table-full-width" id="sample_1">
<thead>
<tr>
<th>Patient ID</th>
<th>Patient Name</th>
<th>Full Name</th>
<th>DOB</th>
<th>Ref. Name</th>
<th>Payment</th>
<th>Doc Status</th>
<th>Appointment</th>
<th>Action</th>
</tr>
</thead>
#foreach($patient_user as $key=>$row)
<tbody>
<tr>
<td>{{$row->patient_id}}</td>
<td>{{$row->patient_firstname}}</td>
<td>{{$row->patient_firstname}} {{$row->patient_lastname}}</td>
<td>{{$row->dob}}</td>
<td>{{$row->refering_physician_name}}</td>
<td>{{$row->dob}} </td>
<td>{{$row->dob}}</td>
<td>{{$row->app_date}}</td>
<td class="center">
<div class="visible-md visible-lg hidden-sm hidden-xs">
<i class="fa fa-edit"></i>
<i class="fa fa-eye"></i>
<i class="fa fa-times fa fa-white"></i>
</div>
</td>
</tr>
</tbody>
#endforeach
</table>
</div>
<div id="static" class="modal fade" tabindex="-1" data-backdrop="static" data-keyboard="false" style="display: none;">
<div class="modal-body">
<h4><i>Patient Details</i></h4>
</div>
<div class="modal-body">
<div class="col-md-12">
<div class="col-md-6">First Name</div>
<div class="col-md-5" id="fname"> {{ $row->patient_firstname}} </div>
</div>
<br>
<div class="col-md-12">
<div class="col-md-6">Middle Name</div>
<div class="col-md-5" id="mname"> {{ $row->middle_name}} </div>
</div>
<br>
<div class="col-md-12">
<div class="col-md-6">Last Name</div>
<div class="col-md-5" id="lname"> {{ $row->patient_lastname}} </div>
</div>
</div>
</div>
</form>
jquery:
<script type="text/javascript">
$('#static').on('show', function(e)
{
e.preventDefault();
var link = e.relatedTarget(),
modal = $(this),
patient_firstname = link.data("patient_firstname"),
middle_name = link.data(middle_name),
patient_lastname = link.data("patient_lastname"),
modal.find("#fname").val(patient_firstname);
modal.find("#mname").val(middle_name);
modal.find("#lname").val(patient_lastname);
});
</script>
where #static is my modal Id and the value within find are the id's of the particular fields and val are the database values.
The problem is that you're requesting data from attributes that are not set.
patient_firstname = link.data("patient_firstname"),
The above part is trying to retrieve the value of the attribute data-patient_firstname. Since the original link does not have this attribute there won't be any data.
Change
<i class="fa fa-eye"></i>
Into
<a href='#' data-toggle="modal"
data-patient_firstname="{{$row->patient_firstname}}" <-- do this for all requested vars
class="btn btn-xs btn-green tooltips" data-id="{{ $row->patient_id}}" data-target="static" onclick="pat_det{{ $row->patient_id }}" data-placement="top" data-original-title="View" id="pat_det"><i class="fa fa-eye"></i></a>
That way the data-* attributes will be availble.
Related
I don't use pure vue in the app. I want to close the modal after sending the data to the database. I cannot close it for anything in the world by examining the divergence of the Internet. Can you help? :)
<div class="container-fluid">
<!-- DIRECT CHAT -->
<div class="card" id="form">
<!-- /.card-header -->
<div class="card-body">
<div class="row">
<!-- Button trigger modal -->
<button type="button" class="btn btn-success" data-toggle="modal" data-target="#exampleModal">
Dodaj budynek
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModal" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Dodawanie budynku</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
#csrf
#{{ info.data }}
<div class="modal-body">
<div class="form-group">
<label>Nazwa budynku <span class="red">*</span></label>
<input type="text" class="form-control" name="name" id="name" v-model="name">
<small>Nazwa identyfikująca budynek, np. ulica i numer budynku lub nazwa własna</small>
<small><div v-if="feedback">
<span style="color:red" v-text="feedback.name[0]" ></span>
</div></small>
</div>
<div class="form-group">
<label>Konto rozliczeniowe</label>
<input type="text" class="form-control" name="bank_account" id="bank_account" v-model="bank_account">
<small>Numer konta bankowego</small>
</div>
<div class="form-group">
<label>Opis</label>
<textarea class="form-control" rows="3" name="description" id="description" v-model="description"></textarea>
<small>Dodatkowe informacje, adnotacje, opis</small>
</div>
<small><span class="red">* pola obowiązkowe</span></small>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Anuluj</button>
<button type="submit" class="btn btn-success" #click="add">Zapisz</button>
</div>
</div>
</div>
</div>
</div>
<div class="row pt-2">
<table class="table table-striped">
<thead>
<tr>
<th scope="col" width="5%">#</th>
<th scope="col" width="25%">Nazwa <i class="fas fa-info-circle fa-sm" rel="tooltip" title="Nazwa pod którą identyfikowana jest zarządzana nieruchomość"></i></th>
<th scope="col" width="30%">Konto księgowe <i class="fas fa-info-circle fa-sm" rel="tooltip" title="Numer konta bankowego"></i></th>
<th scope="col" width="30%">Opis <i class="fas fa-info-circle fa-sm" rel="tooltip" title="Opis identyfikujący lub uzupełniający nazwę zarządzanej nieruchomości"></i></th>
<th width="5%"></th>
<th width="5%"></th>
</tr>
</thead>
<tbody>
<tr v-for="(list, index) in lists" :key="list.id">
<th scope="row">#{{ index + 1 }}</th>
<td>#{{ list.name }}</td>
<td>#{{ list.bank_account }}</td>
<td>#{{ list.description }}</td>
<td><button type="button" class="btn btn-info btn-sm"><i class="fas fa-pencil-alt"></i></button></td>
<td><button type="button" class="btn btn-danger btn-sm" #click="deleteData(list.id)"><i class="far fa-trash-alt"></i></button></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
I present script vue below. After running the add method, I would like to close the modal.
<script>
const app = new Vue({
el: '#form',
data () {
return {
feedback: '',
name: '',
bank_account: '',
description: '',
info: '',
lists: [],
}
},
mounted: function(){
this.show();
},
methods: {
show:function(list){
axios
.get('buildings/show', {
})
.then(({ data }) => (this.lists = data));
},
add () {
axios
.post('buildings/store', {
name: this.name,
bank_account: this.bank_account,
description: this.description,
})
.then(response => {
this.show();
this.name = '';
this.bank_account = '';
this.description = '';
this.info = response;
this.myModal.hide();
})
.catch(error => {
this.feedback = error.response.data.errors;
this.info = '';
})
},
deleteData:function(id){
axios
.post('buildings/destroy', {
id: id
})
.then(response => {
this.show();
})
.catch(error => {})
},
},
})
</script>
I wonder how to edit the code so that after calling the add method, the modal will close. I don't want to write in pure vue.js because I haven't grasped this topic yet.
I'm assuming you're using bootstrap modals here?
In your add() method you have this: this.myModal.hide(); but myModal is not defined anywhere.
In your modal html you can add a ref:
<div class="modal fade" ref="myModal" id="exampleModal">
Then you can use this to close the modal:
this.$refs.myModal.hide();
You can take little help of jquery if you already have it.
let currentOpenModel= jQuery('.modal.in').attr('id');
// modalID or undefined
jQuery('#' + currentOpenModel)?.modal('hide');
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 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>
The following is my controller Wordings_test.php code
The issue is I am not able to print #wording.product. Even though, I can print #wording.template_name.
Thanks
class Wordings_test extends Controller{
function show($f3)
{
$wordings = Wordings::all()->orderBy('id')->select()->toArray();
foreach ($wordings as $wording) {
$wording['product'] = ProductTypes::where(['id' =>
$wording['product_type_id']])->select()->getAttribute('name');
}
$f3->set('wordings',$wordings);
$this->render('admin/wordings/view')
}
The following is the template code view.html
<i class="fa fa-user-plus"></i> Add New Brokerage Head Group
<div class="row">
<div class="form-group">
<div class="tab-content">
<div id="brokerageheadlist" class="active in tab-pane fade">
<table class="table table-bordered adminTable" id="brokerageheadList">
<thead>
<tr>
<th>Wording</th>
<th>Product Type</th>
<th style="width:140px;">Controls</th>
</tr>
</thead>
<tbody>
<repeat group="{{ #wordings }}" value="{{ #wording }}">
<tr>
<td>{{ #wording.template_name }}</td>
<td>
{{ #wording.product }}
</td>
<td>
<a class="btn btn-sm btn-info showLoader" href="/admin/wordings/edit-wordings/{{ #wording.id }}">Edit</a>
<button type="button" class="btn btn-danger btn-sm" data-toggle="modal" data-target="#myModal{{#brokeragehead.id}}">Delete</button>
<div id="myModal{{#brokeragehead.id}}" class="modal fade" role="dialog">
<div class="modal-dialog">
Please help me solve my problem in my delete file in my project i am confuse because it always return me a null value
here is my editfile.blade.php
#include('partials.navbar')
<link rel="stylesheet" type="text/css" href="http://localhost:8000/assets/css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="http://localhost:8000/assets/css/search.css">
<!-- Search -->
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="input-group" id="adv-search">
<input type="text" class="form-control" placeholder="Search file" />
<div class="input-group-btn">
<div class="btn-group" role="group">
<div class="dropdown dropdown-lg">
<button type="button" class="set-width btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false"><span class="caret"></span></button>
<div class="dropdown-menu dropdown-menu-right" role="menu">
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="file">File type</label>
<select class="form-control">
<option value="pf">Public Weather Forecast</option>
<option value="sf">24 Shipping Forecast</option>
<option value="gale">Gale Warning Forecast</option>
<option value="advisory">Weather Advisory</option>
<option value="tca">Tropical Cyclone Advisory</option>
<option value="swb">Severe Weather Bulletin</option>
<option value="iws">International Warning for shipping</option>
<option value="wof">Weather Outlook Forecast</option>
<option value="spf">Special Forecast</option>
<option value="sm">Surface Maps</option>
</select>
</div>
<div class="form-group">
<label for="contain">Date</label>
<input class="form-control" type="date" />
</div>
<div class="form-group">
<label for="contain">Contains the words</label>
<input class="form-control" type="text" />
</div>
<button type="submit" class="btn btn-primary"><i class="fa fa-search"></i></button>
</form>
</div>
</div>
<button type="button" class="btn btn-primary"><i class="fa fa-search"></i></button>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- datatable-->
<div class="container">
<div class="row">
<div class="col-md-12">
<h4>File Management</h4>
<table id="mytable2" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<thead>
<tr>
<th>File Name</th>
<th>Date Issued</th>
<th>Uploader</th>
<th>Actions</th>
</tr>
</thead>
<tfoot>
<tr>
<th>File Name</th>
<th>Date Issued</th>
<th>Uploader</th>
<th>Actions</th>
</tr>
</tfoot>
<tbody>
<tbody>
#foreach ($files as $files3)
<tr>
<td>{{ $files3->file_name }}</td>
<td>{{ $files3->date }}</td>
<td>{{ $files3->username }}</td>
<td></i>
<button data-id="{{ $files3->id }}" class="btn btn-danger btn-xs delete-button" data-title="Delete" data-toggle="modal" data-target="#delete-modal" ><i class="fa fa-trash"></i></button></td>
</tr>
#endforeach
</tbody>
</table>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="delete-modal" tabindex="-1" role="dialog" aria-labelledby="delete-modal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i></button>
<h4 class="modal-title custom_align" id="Heading">Delete this file record</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" action="/deletefile" method="post">
<input name="deletefileid" type="hidden" id="deletefileid" value="">
<div class="alert alert-danger"><i class="fa fa-exclamation-triangle"></i> Are you sure you want to delete this Record?</div>
</div>
<div class="modal-footer ">
<button type="submit" class="btn btn-success" ><i class="fa fa-check"></i> Yes</button>
<button type="submit" class="btn btn-default" data-dismiss="modal"><i class="fa fa-times"></i> No</button>
</form>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
</div>
</div>
</div>
#include('partials.footer')
<script type="text/javascript" src="http://localhost:8000/assets/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="http://localhost:8000/assets/js/datatable2.js"></script>
<script src="http://localhost:8000/assets/js/modernizr-custom.js"></script>
<!-- polyfiller file to detect and load polyfills -->
<script src="http://localhost:8000/assets/js/polyfiller.js"></script>
<script>
webshims.setOptions('waitReady', false);
webshims.setOptions('forms-ext', {types: 'date'});
webshims.polyfill('forms forms-ext');
</script>
<script>
$(function() {
$(".delete-button").click(function(){
var param = $(this).data('id');
$.ajax({
url: "/erasefile/" + param,
success: function(msg){
var info = JSON.parse(msg)[0];
console.log(info);
$('#deletefileid').val(info.id);
},
error:function(){
alert("failure");
}
});
});
});
</script>
here is my model file.php
public static function getdeleteFiles($deleteid)
{
$files = Files::find($deleteid);
$files->delete();
}
here is my Controller FileController.php
public function eraseFile($id)
{
$files = Files::where('id',$id)
->get();
return json_encode($files);
}
public function deleteFile()
{
dd(Input::all());
$ftype = Input::get('type');
$oldfile = Input::get('oldfile');
$deleteid = Input::get('deleteid');
$delete = Files::getdeleteFiles($deleteid);
//dd($deleteid);
if ($delete == true) {
File::delete(public_path("uploads/{$ftype}/{$oldfile}"));
return Redirect::to('/edit');
} else {
return Redirect::back()->with('message', 'Delete, Failed');
}
}
and here is my route
Route::get('/erasefile/{id}', 'FileController#eraseFile');
Route::post('/deletefile', array('uses' => 'FileController#deleteFile'));
Please help me solve this TIA!
the input and select elements in your form does not have a name attribute
your function didn't return any value
public static function getdeleteFiles($deleteid)
{
$files = Files::find($deleteid);
$files->delete();
}
maybe should be
public static function getdeleteFiles($deleteid)
{
$files = Files::find($deleteid);
return $files->delete();
}