GET not supported although I am using PUT in Laravel - php

I am using Laravel 7 and I can add entries and view them from the database. When I try to edit or update edited changes, I either get a warning from Laravel saying that the The GET method is not supported for this route. Supported methods: PUT. However, I am using PUT in both the web.php route as well as in my method calls. Surely I am doing something wrong.
Here is a view of my Routes calling artisan route:list
in my Route Group in web.php Here are the controllers I am calling:
Route::group(['middleware' => ['auth', 'isAdmin']], function () {
Route::get('/dashboard', function () {
return view('admin.dashboard');
});
Route::get('registered-user', 'Admin\RegisteredController#index');
Route::get('registered-empresa', 'Admin\EmpresaController#index');
Route::get('role-edit/{id}', 'Admin\RegisteredController#edit');
Route::put('role-update/{id}', 'Admin\RegisteredController#updaterole');
Route::post('save-empresa', 'Admin\EmpresaController#store');
Route::put('edit-empresa/{id}', 'Admin\EmpresaController#update');
});
Here is the update function I created in EmpresaController.php:
public function update(Request $request, $id)
{
$this->validate($request, [
'erfc' => 'required',
'enombre' => 'required',
'ecalle' => 'required',
'ecolonia' => 'required',
'eciudad' => 'required',
'eestado' => 'required',
'ecpostal' => 'required',
'epais' => 'required',
]);
$empr = Empresa::find($id);
$empr->erfc = $request->input('erfc');
$empr->enombre = $request->input('enombre');
$empr->ecalle = $request->input('ecalle');
$empr->ecolonia = $request->input('ecolonia');
$empr->eciudad = $request->input('eciudad');
$empr->eestado = $request->input('eestado');
$empr->ecpostal = $request->input('ecpostal');
$empr->epais = $request->input('epais');
$empr->update();
return redirect('/registered-empresa')->with('status', 'Empresa se actualizó correctamente.');
}
And finally, here is the location of my empresas table where I both add, view and update my table in my index.blade.php file:
#extends('layouts.admin')
#section('content')
<div class="container-fluid mt-5">
<!-- Heading -->
<div class="card mb-4 wow fadeIn">
<!--Card content-->
<div class="card-body d-sm-flex justify-content-between">
<h4 class="mb-2 mb-sm-0 pt-1">
Home Page
<span>/</span>
<span>Empresas Registradas</span>
</h4>
#if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
#endif
<div class="modal fade" id="modalRegisterForm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header text-center">
<h4 class="modal-title w-100 font-weight-bold">Añadir Empresa</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form action="/save-empresa" method="POST">
{{ csrf_field() }}
<div class="modal-body mx-3">
<div class="md-form mb-1">
<input type="text" name="erfc" id="orangeForm-erfc" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-erfc">RFC</label>
</div>
<div class="md-form mb-1">
<input type="text" name="enombre" id="orangeForm-enombre" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-enombre">Nombre</label>
</div>
<div class="md-form mb-1">
<input type="text" name="ecalle" id="orangeForm-ecalle" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-ecalle">Calle</label>
</div>
<div class="md-form mb-1">
<input type="text" name="ecolonia" id="orangeForm-ecolonia" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-ecolonia">Colonia</label>
</div>
<div class="md-form mb-1">
<input type="text" name="eciudad" id="orangeForm-eciudad" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-eciudad">Ciudad</label>
</div>
<div class="md-form mb-1">
<input type="text" name="eestado" id="orangeForm-eestado" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-eestado">Estado</label>
</div>
<div class="md-form mb-1">
<input type="text" name="ecpostal" id="orangeForm-ecpostal" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-ecpostal">Codigo Postal</label>
</div>
<div class="md-form mb-1">
<input type="text" name="epais" id="orangeForm-epais" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-epais">País</label>
</div>
<div style="display: none;" class="md-form mb-1">
<input type="text" name="euser" readonly id="orangeForm-euser" class="form-control validate" value="{{ Auth::user()->id }}">
</div>
<div style="display: none;" class="md-form mb-1">
<input type="text" name="eregby" readonly id="orangeForm-eregby" class="form-control validate" value="{{ Auth::user()->id }}">
</div>
</div>
<div class="modal-footer d-flex justify-content-center">
<button type="submit" class="btn btn-deep-orange">Añadir</button>
</div>
</form>
</div>
</div>
</div>
<div class="text-center">
<i class="fa fa-plus" aria-hidden="true"></i> Add
</div>
<!--edit modal start-->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header text-center">
<h4 class="modal-title w-100 font-weight-bold">Editar Empresa</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form action="edit-empresa/" id="editForm">
{{ csrf_field() }}
#method('PUT')
<div class="modal-body mx-3">
<div class="md-form mb-1">
<input placeholder="RFC" type="text" name="erfc" id="erfc" class="form-control validate">
</div>
<div class="md-form mb-1">
<input placeholder="Nombre" type="text" name="enombre" id="enombre" class="form-control validate">
</div>
<div class="md-form mb-1">
<input placeholder="Calle" type="text" name="ecalle" id="ecalle" class="form-control validate">
</div>
<div class="md-form mb-1">
<input placeholder="Colonia" type="text" name="ecolonia" id="ecolonia" class="form-control validate">
</div>
<div class="md-form mb-1">
<input placeholder="Ciudad" type="text" name="eciudad" id="eciudad" class="form-control validate">
</div>
<div class="md-form mb-1">
<input placeholder="Estado" type="text" name="eestado" id="eestado" class="form-control validate">
</div>
<div class="md-form mb-1">
<input placeholder="Codigo Postal" type="text" name="ecpostal" id="ecpostal" class="form-control validate">
</div>
<div class="md-form mb-1">
<input placeholder="País" type="text" name="epais" id="epais" class="form-control validate">
</div>
<div style="display: none;" class="md-form mb-1">
<input type="text" name="euser" readonly id="euser" class="form-control validate" value="{{ Auth::user()->id }}">
</div>
<div style="display: none;" class="md-form mb-1">
<input type="text" name="eregby" readonly id="eregby" class="form-control validate" value="{{ Auth::user()->id }}">
</div>
</div>
{{-- <div class="modal-footer d-flex justify-content-center">
<button type="submit" class="btn btn-deep-orange">Editar</button>
</div> --}}
<div class="modal-footer d-flex justify-content-center">
<button type="submit" class="btn btn-deep-orange">Editar</button>
</div>
</form>
</div>
</div>
</div>
<!--end edit modal-->
</div>
</div>
<!-- Heading -->
<!--Grid row-->
<!--Grid column-->
<div class="row">
<!--Card-->
<div class="col-md-12 mb-4">
<!--Card content-->
<div class="card">
<!-- List group links -->
<div class="card-body">
<table id="datatable2" class="table table-bordered">
<thead>
<tr>
<th>RFC</th>
<th>Nombre</th>
<th>Calle</th>
<th>Colonia</th>
<th>Ciudad</th>
<th>Estado</th>
<th>Codigo Postal</th>
<th>País</th>
<th>Acción</th>
</tr>
</thead>
<tbody>
#foreach ($empresas as $empresa)
<tr>
<td>{{ $empresa->erfc }}</td>
<td>{{ $empresa->enombre }}</td>
<td>{{ $empresa->ecalle }}</td>
<td>{{ $empresa->ecolonia }}</td>
<td>{{ $empresa->eciudad }}</td>
<td>{{ $empresa->eestado }}</td>
<td>{{ $empresa->ecpostal }}</td>
<td>{{ $empresa->epais }}</td>
<td>
<div class="text-center">
Editar
<a class="badge badge-pill btn-danger px-3 py-2" href="">Borrar</a>
</div>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
<!-- List group links -->
</div>
</div>
<!--/.Card-->
</div>
<!--Grid row-->
</div>
#endsection
#section('scripts')
<script>
$(document).ready(function() {
let table = $('#datatable2').DataTable();
// Start edit record
table.on('click', '.edit', function() {
$tr = $(this).closest('tr');
if($($tr).hasClass('child')) {
$tr = $tr.prev('.parent');
}
let data = table.row($tr).data();
console.log(data);
$('#erfc').val(data[0]);
$('#enombre').val(data[1]);
$('#ecalle').val(data[2]);
$('#ecolonia').val(data[3]);
$('#eciudad').val(data[4]);
$('#eestado').val(data[5]);
$('#ecpostal').val(data[6]);
$('#epais').val(data[7]);
$('#editForm').attr('action', '/edit-empresa/'+data[0]);
$('#editModal').modal('show');
});
// End edit record
});
</script>
#endsection
I am pretty sure it is in this file that I am doing something wrong. Any help on how I can do this better or if I missed something, I would surely appreciate it. Thank you in advance.

in web.php
Route::patch('edit-empresa/{id}', 'Admin\EmpresaController#update');
index.blade.php
#method('PATCH')

You need to specify method as POST when defining the form even though you are including the #method('PUT') inside the form. That is because HTML does not support PUT method directly, and by default it will be a GET. So to correct:
Change this:
<form action="edit-empresa/" id="editForm">
TO
<form action="edit-empresa/" id="editForm" method="POST">

For some reason I could not get this to work using the modal and jquery method so I eliminated the datatables jquery from the bottom of the index.blade.php. My first error was to not call the data first. I created a seperate file called edit.blade.php within the view-admin-empresa folder. Here is the code:
#extends('layouts.admin')
#section('content')
<div class="container-fluid mt-5">
<!-- Heading -->
<div class="card mb-4 wow fadeIn">
<!--Card content-->
<div class="card-body d-sm-flex justify-content-between">
<h4 class="mb-2 mb-sm-0 pt-1">
<span>Empresa Registrada - Editar Empresa</span>
</h4>
</div>
</div>
<!-- Heading -->
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">Editar Empresa</h4>
<form action="{{ url('empresa-update/'.$empresa->id) }}" id="editForm" method="POST">
{{ csrf_field() }}
{{ method_field('PUT') }}
<div class="modal-body mx-3">
<div class="md-form mb-1">
<label for="erfc">RFC</label>
<input value="{{ $empresa->erfc }}" type="text" name="erfc" id="erfc" class="form-control validate">
</div>
<div class="md-form mb-1">
<label for="enombre">Nombre</label>
<input value="{{ $empresa->enombre }}" type="text" name="enombre" id="enombre" class="form-control validate">
</div>
<div class="md-form mb-1">
<label for="ecalle">Calle</label>
<input value="{{ $empresa->ecalle }}" type="text" name="ecalle" id="ecalle" class="form-control validate">
</div>
<div class="md-form mb-1">
<label for="ecolonia">Colonia</label>
<input value="{{ $empresa->ecolonia }}" type="text" name="ecolonia" id="ecolonia" class="form-control validate">
</div>
<div class="md-form mb-1">
<label for="ecuidad">Ciudad</label>
<input value="{{ $empresa->eciudad }}" type="text" name="eciudad" id="eciudad" class="form-control validate">
</div>
<div class="md-form mb-1">
<label for="eestado">Estado</label>
<input value="{{ $empresa->eestado }}" type="text" name="eestado" id="eestado" class="form-control validate">
</div>
<div class="md-form mb-1">
<label for="ecpostal">Codigo Postal</label>
<input value="{{ $empresa->ecpostal }}" type="text" name="ecpostal" id="ecpostal" class="form-control validate">
</div>
<div class="md-form mb-1">
<label for="epais">País</label>
<input value="{{ $empresa->epais }}" type="text" name="epais" id="epais" class="form-control validate">
</div>
<div style="display: none;" class="md-form mb-1">
<input type="text" name="euser" readonly id="euser" class="form-control validate" value="{{ Auth::user()->id }}">
</div>
<div style="display: none;" class="md-form mb-1">
<input type="text" name="eregby" readonly id="eregby" class="form-control validate" value="{{ Auth::user()->id }}">
</div>
</div>
<div class="modal-footer d-flex justify-content-center">
Cancelar
<button type="submit" class="btn btn-deep-orange">Editar</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
Then in the web.php, I created the following routes:
Route::group(['middleware' => ['auth', 'isAdmin']], function () {
Route::get('/dashboard', function () {
return view('admin.dashboard');
});
Route::get('registered-user', 'Admin\RegisteredController#index');
Route::get('registered-empresa', 'Admin\EmpresaController#index');
Route::get('role-edit/{id}', 'Admin\RegisteredController#edit');
Route::put('role-update/{id}', 'Admin\RegisteredController#updaterole');
Route::post('save-empresa', 'Admin\EmpresaController#store');
Route::get('/edit-empresa/{id}', 'Admin\EmpresaController#edit');
Route::put('/empresa-update/{id}', 'Admin\EmpresaController#update');
});
As mentioned earlier, I eliminated the edit modal and redirected to the empresa edit.blade.php file.
Now, I am able to edit without any problems. Thank you to Arjun bhati and user3532758 for taking a stab at this issue. I really appreciate it.

Related

Laravel: Attempt to read property "customer_name" on bool

I'm new to laravel. I have to edit a form that contains a dropdown list. Edit form works fine works without the dropdown input. Updating with dropdown input throws the above error.
controller:
public function edit(QR_details $qR_detail)
{
return view('pages.edit_QR_details')->with('qr_details', $qR_detail);
}
public function update(Request $request, QR_details $qR_details)
{
$qR_details->update($request->all());
toastr()->success('QR Detail updated successfully');
return redirect()->route(('QR_code_details.index'));
}
Edit form:
form action="{{ route('QR_code_details.update', $qr_details->id) }}" method="POST" class="">
#csrf
#method("PATCH")
<div class="px-3 form-row">
<div class="form-group p-2 col-5">
<label for="" class="form-label fw-bold text-secondary">Customer Name*</label>
<select name="customer_name" class="form-select shadow" name="" id="">
#foreach ($qr_details as $qr_detail)
<option value="{{ $qr_detail->customer_name }}">{{ $qr_detail->customer_name }}</option>
#endforeach
</select>
</div>
<div class="form-group p-2 col-6">
<label for="" class="form-label text-secondary fw-bold">Background Image</label>
<input type="file" name="background image" class="form-control shadow" value="{{ $qr_details->background_image }}">
</div>
<div class="form-group p-2 col-6">
<label for="" class="form-label text-secondary fw-bold">Create QR Code</label>
<input type="file" name="create_qr_code" class="form-control shadow" value="{{ $qr_details->create_qr_code }}">
</div>
<div class="form-group p-2 col-6">
<label for="" class="form-label text-secondary fw-bold">Movable QR</label>
<input type="file" name="movable_qr" class="form-control shadow" value="{{ $qr_details->maovable_qr }}">
</div>
<div class="row ">
<div class="mt-4 col">
<button class="btn bg-gradient-danger btn-sm btn-rounded">Cancel</button>
</div>
<div class=" col mt-4">
<button class="btn bg-gradient-success btn-sm btn-rounded">Save</button>
</div>
</div>
</div>
</form>
Route:
Route::get('QR_code_detail_edit-{qR_detail}', [QRDetailsController::class, 'edit'])->name('QR_code_details.edit');
Route::post('QR_code_detail_edit-{qR_detail}', [QRDetailsController::class, 'update'])->name('QR_code_details.update');
Can someone help me out, how it should be done ?

Laravel display image uploaded in view from database

I want to display images uploaded in view file to the database using laravel...the image are not loaded...
below is my view file where i want to display my image
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
#foreach($infor as $inform)
<div class="card mb-3">
<img src="{{ asset('storage/uploads/'.$inform->imogi) }}" style="max-width:20%;" alt="Wild Landscape"/>
<div class="card-body">
<div style="text-align: right;">
<small style="color:#3490dc;">{{$inform->organazation}}</small> <small><i class="fa fa-calendar" style="color:#3490dc" aria-hidden="true"></i> {{ $inform->created_at->format('d/m/Y') }}</small>
</div>
<h5 class="card-title"><i class="fa fa-user-circle-o" style="color:#3490dc" aria-hidden="true"></i> {{$inform->name}}</h5>
<!--LIVEWIRE online status-->
<div wire:key="UNIQUE_ID">
#if($inform->isOnline())
<small style="color:#3490dc;"> operative </small>
#else
<small style="color:#3490dc;"> detached</small>
#endif
</div>
<small><i class="fa fa-map-marker" style="color:#3490dc" aria-hidden="true"></i> {{$inform->location}}</small>
<hr/>
<h6 class="card-title"><b>{{$inform->title}}</b></h6>
<p class="card-text">
{{$inform->message}}
</p>
<small><small style="color:#3490dc;"><u><b>Qualifications:</b></u></small> {{$inform->qualifications}}</small>
<div style="text-align: right;">
<small><i class="fa fa-phone" style="color:#3490dc" aria-hidden="true"></i> {{$inform->contact}}</small>
</div>
</div>
</div>
<br/>
#endforeach
</div>
</div>
</div>
#include('footer')
#endsection
below is my upload controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class FileUploadController extends Controller
{
public function fileUpload()
{
return view('fileUpload');
}
//
public function fileUploadPost(Request $request)
{
$request->validate([
'file' => 'required|mimes:pdf,xlx,csv|max:2048',
]);
$fileName = time().'.'.$request->file->extension();
$request->file->move(public_path('uploads'), $fileName);
return back()
->with('success','You have successfully upload file.')
->with('file',$fileName);
}
}
Here is my storage path in filesystems.php
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
And below is the blade view where the image is being uploaded
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<form action="message" method="POST">
#csrf
<div class="form-group">
<label for="exampleFormControlInput1"><i style="color:#3490dc" class="fa fa-user" style="font-size:24px"></i> Name</label>
<input type="text" class="form-control" id="exampleFormControlInput1" name="name" value="{{ auth()->user()->name }}" readonly>
</div>
<div class="form-group">
<label for="exampleFormControlInput1"><i style="color:#3490dc" class="fa fa-building-o" style="font-size:24px"></i> Organazation</label>
<input type="text" class="form-control" id="exampleFormControlInput1" name="organazation">
<span style="color: red;"><small>#error('organazation'){{$message}}#enderror</small></span>
<small>Type your organazation or state whether individual</small>
</div>
<div class="form-group">
<label for="exampleFormControlInput1"><i style="color:#3490dc" class="fa fa-map-marker" style="font-size:24px"></i> Location</label>
<input type="text" class="form-control" id="exampleFormControlInput1" name="location">
<span style="color: red;"><small>#error('location'){{$message}}#enderror</small></span>
<small>Type your location</small>
</div>
<div class="form-group">
<label for="exampleFormControlInput1"><i style="color:#3490dc" class="fa fa-pencil" style="font-size:24px"></i> Job title</label>
<input type="text" class="form-control" id="exampleFormControlInput1" name="title">
<span style="color: red;"><small>#error('title'){{$message}}#enderror</small></span>
<small>Enter the title for the job</small>
</div>
<div class="form-group">
<label for="exampleFormControlTextarea1"><i style="color:#3490dc" class="fa fa-pencil" style="font-size:24px"></i> Job description</label>
<textarea type="text" class="form-control" id="exampleFormControlTextarea1" rows="3" name="message"></textarea>
<span style="color: red;"><small>#error('message'){{$message}}#enderror</small></span>
<small>Describe the type of job being offered</small>
</div>
<div class="form-group">
<label for="exampleFormControlInput1"><i style="color:#3490dc" class="fa fa-file" style="font-size:24px"></i> Qualifications</label>
<input type="text" class="form-control" id="exampleFormControlInput1" name="qualifications">
<span style="color: red;"><small>#error('qualifications'){{$message}}#enderror</small></span>
<small>Enter the qualifications and experience required</small>
</div>
<div class="form-group">
<label for="exampleFormControlInput1"><i style="color:#3490dc" class="fa fa-phone" style="font-size:24px"></i> Contacts</label>
<input type="text" class="form-control" id="exampleFormControlInput1" name="contact">
<span style="color: red;"><small>#error('contact'){{$message}}#enderror</small></span>
<small>Enter phone contacts</small>
</div>
<form action="{{ route('file.upload.post') }}" method="POST" enctype="multipart/form-data">
#csrf
<div class="row">
<div class="col-md-6">
<input type="file" class="form-control" name="imogi">
</div>
</div>
<span style="color: red;"><small>#error('imogi'){{$message}}#enderror</small></span>
<small>Select business logo if any or implicating image</small>
<br/>
<br/>
<button type="submit" class="btn btn-primary">Post</button>
</form>
<br/>
</form>
</div>
</div>
</div>
#include('footer')
#endsection
I can display any image in my view except the one i uploaded...i dont know where am getting this wrong...i will appreciate any kind of help
Thank You!
you should try:
{{ URL::asset('storage/uploads/'.$inform->imogi) }}

Trying to get property 'nama_member' of non-object in my Laravel project

I have trouble in my view Blade, what's wrong with my code, am I wrong to write code in the controller or in my code model was I declare?
the error said
Trying to get property 'nama_member' of non-object (View:
C:\xampp\htdocs\rezkastore\resources\views\pages\daftar_pelanggan.blade.php)
Blade/View
#extends('layouts.app')
#section('title', 'Daftar Pelanggan')
#section('content')
<div class="header bg-primary pb-6">
<div class="container-fluid">
<div class="header-body"> </div>
</div>
</div>
<div class="container-fluid mt--6">
<!-- Table -->
<div class="row">
<div class="col">
<div class="card">
<!-- Card header -->
<div class="card-header">
<div class="row align-items-center py-0">
<div class="col-lg-6 col-7">
<h6 class="h2 d-inline-block mb-0">Data Pelanggan</h6>
</div>
<div class="col-lg-6 col-5 text-right">
<button class="btn btn-icon btn-primary" type="button" data-toggle="modal" data-target="#addModal">
<span class="btn-inner--icon"><i class="fa fa-plus-circle" aria-hidden="true"></i></span>
<span class="btn-inner--text">Tambah Data</span>
</button>
</div>
</div>
</div>
<div class="table-responsive py-4">
<table class="table table-flush" id="datatable-basic">
<thead class="thead-light">
<tr>
<th width="30px">No</th>
<th>Nama Produk</th>
<th>Alamat</th>
<th>No.Telp</th>
<th>Member</th>
<th>Menu</th>
</tr>
</thead>
<tfoot>
<tr>
<th width="20px">No</th>
<th>Nama</th>
<th>Alamat</th>
<th>No.Telp</th>
<th>Member</th>
<th>Menu</th>
</tr>
</tfoot>
<tbody>
#php
$no = 1;
#endphp
#foreach($daftar_pelanggan as $pelanggan)
<tr>
<td>{{$no++ }}</td>
<td>{{ $pelanggan->nama_pelanggan }}</td>
<td>{{ $pelanggan->alamat }}</td>
<td>{{ $pelanggan->no_telp }}</td>
<td> {{ $pelanggan->diskon->nama_member }}</td>
<td>
<button data-toggle="modal" data-target="#editModal-{{ $pelanggan->id }}" class="btn btn-sm btn-primary"><i class="fa fa-edit"></i></button>
<button class="btn btn-sm btn-danger" type="button" onclick="deletepelanggan({{ $pelanggan->id }})"> <i class="fa fa-trash"></i>
</button>
<form id="delete-form-{{ $pelanggan->id }}" action="{{ route('daftar_pelanggan.delete',$pelanggan->id) }}" method="POST" style="display: none;">
#csrf
#method('DELETE')
</form>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- Modal Add -->
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="addModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title mb-0" id="addModalLabel">Tambah Data Pelanggan</h5>
</div>
<div class="modal-body">
<!-- Card body -->
<form role="form" action="{{ route('daftar_pelanggan.create') }}" method="POST">
#csrf
#method('POST')
<!-- Input groups with icon -->
<div class="form-group row">
<label for="addNamaPelanggan" class="col-md-4 col-form-label form-control-label">Nama <span class="text-danger">*</span></label>
<div class="col-md-8">
<input class="form-control" type="nama" placeholder="Nama Lengkap" id="addNamaPelanggan" name="addNamaPelanggan" required oninvalid="this.setCustomValidity('data tidak boleh kosong')" oninput="setCustomValidity('')">
</div>
</div>
<div class="form-group row">
<label for="addAlamat" class="col-md-4 col-form-label form-control-label">Alamat <span class="text-danger">*</span></label>
<div class="col-md-8">
<input class="form-control" type="alamat" placeholder="Jatibarang" id="addAlamat" name="addAlamat" required oninvalid="this.setCustomValidity('data tidak boleh kosong')" oninput="setCustomValidity('')">
</div>
</div>
<div class="form-group row">
<label for="addNoTelp" class="col-md-4 col-form-label form-control-label">No.Telp <span class="text-danger">*</span></label>
<div class="col-md-8">
<input class="form-control" type="notelp" placeholder="083XXXXXXXXX" id="addNoTelp" name="addNoTelp" required oninvalid="this.setCustomValidity('data tidak boleh kosong')" oninput="setCustomValidity('')">
</div>
</div>
<div class="form-group row">
<label for="addNoTelp" class="col-md-4 col-form-label form-control-label">diskon Member <span class="text-danger">*</span></label>
<div class="col-md-8">
<select class="form-control" name="AddDiskonid" required oninvalid="this.setCustomValidity('data tidak boleh kosong')" oninput="setCustomValidity('')"">
<option disabled selected>-- Pilih Member --</option>
#foreach($diskons as $diskon)
<option value="{{ $diskon->id }}">{{ $diskon->nama_member }}</option>
#endforeach
</select>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Tambah Data</button>
</div>
</form>
</div>
</div>
</div>
<!-- Modal edit -->
#foreach($daftar_pelanggan as $pelanggan)
<div class="modal fade" id="editModal-{{ $pelanggan->id }}" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title mb-0" id="editModalLabel">Update Data Pelanggan</h5>
</div>
<div class="modal-body">
<!-- Card body -->
<form role="form" action="{{ route('daftar_pelanggan.update', $pelanggan->id) }}" method="POST" id="editForm">
#csrf
#method('PUT')
<!-- Input groups with icon -->
<div class="form-group row">
<label for="updateNamaPelanggan" class="col-md-4 col-form-label form-control-label">Nama <span class="text-danger">*</span></label>
<div class="col-md-8">
<input type="hidden" name="id" value="{{ $pelanggan->id }}">
<input class="form-control" type="nama" value="{{ $pelanggan->nama_pelanggan }}" name="updateNamaPelanggan" required >
</div>
</div>
<div class="form-group row">
<label for="updateAlamat" class="col-md-4 col-form-label form-control-label">Alamat <span class="text-danger">*</span></label>
<div class="col-md-8">
<input class="form-control" type="alamat" value="{{ $pelanggan->alamat }}" name="updateAlamat" required>
</div>
</div>
<div class="form-group row">
<label for="updateNoTelp" class="col-md-4 col-form-label form-control-label">No.Telp <span class="text-danger">*</span></label>
<div class="col-md-8">
<input class="form-control" type="notelp" value="{{ $pelanggan->no_telp }}" name="updateNoTelp" required>
</div>
</div>
<div class="form-group row">
<label for="addNoTelp" class="col-md-4 col-form-label form-control-label">Diskon Member <span class="text-danger">*</span></label>
<div class="col-md-8">
<select class="form-control" name="diskon_id" required oninvalid="this.setCustomValidity('data tidak boleh kosong')" oninput="setCustomValidity('')">
<option disabled selected>-- Kategori Member --</option>
#foreach($diskons as $diskon)
<option
#if($produk->diskon_id == $diskon->id)
selected="selected"
#endif
value="{{ $diskon->id }}">{{ $diskon->nama_member }}</option>
#endforeach
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Update Data</button>
</div>
</form>
</div>
</div>
</div>
#endforeach
#include('layouts.footers.auth')
#section('scripts')
<script type="text/javascript">
function deletepelanggan(id) {
swal({
title: 'Yakin Ingin Hapus Data ini?',
text: "Data Tidak Bisa Dikembalikan Setelah Dihapus!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Ya, Hapus!',
cancelButtonText: 'Tidak',
confirmButtonClass: 'btn btn-success',
cancelButtonClass: 'btn btn-danger',
buttonsStyling: false,
reverseButtons: true
}).then((result) => {
if (result.value) {
event.preventDefault();
document.getElementById('delete-form-'+id).submit();
swal(
'Deleted!',
'Your file has been deleted.',
'success')
} else (
result.dismiss === swal.DismissReason.cancel
)
})
}
</script>
#endsection
#endsection
Controller
class DaftarPelangganController extends Controller
{
public function index()
{
$daftar_pelanggan = DaftarPelanggan::all();
$diskons = Diskon::all();
return view('pages.daftar_pelanggan', compact('daftar_pelanggan', 'diskons'));
}
public function update(Request $request, $id)
{
$update_pelanggan = DaftarPelanggan::findOrFail($id);
$update_pelanggan->nama_pelanggan = $request->updateNamaPelanggan;
$update_pelanggan->alamat = $request->updateAlamat;
$update_pelanggan->no_telp = $request->updateNoTelp;
$update_pelanggan->diskon_id = $request->diskon_id;
$update_pelanggan->save();
if ($update_pelanggan) {
Alert::success(' Berhasil Update Data ', ' Silahkan dicek kembali');
} elseif (!$update_pelanggan) {
Alert::error('Data Sudah Ada', ' Silahkan coba lagi');
}
return redirect()->back();
}
public function create(Request $request)
{
$simpan = DB::table('daftar_pelanggans')->insert([
'nama_pelanggan' => $request->post('addNamaPelanggan'),
'alamat' => $request->post('addAlamat'),
'no_telp' => $request->post('addNoTelp'),
'diskon_id' => $request->post('addDiskonid'),
]);
if ($simpan) {
Alert::success(' Berhasil Tambah data ', ' Silahkan dicek kembali');
} else {
Alert::error('data gagal disimpan ', ' Silahkan coba lagi');
}
return redirect()->back();
}
public function delete($id)
{
DB::table('daftar_pelanggans')->where('id', $id)->delete();
return redirect()->back();
}
}
Model
class DaftarPelanggan extends Model
{
use HasFactory;
protected $table = "daftar_pelanggans";
protected $primaryKey = 'id';
protected $fillable = [
'nama_pelanggan',
'alamat',
'no_telp',
'poin',
'diskon_id',
];
public function diskon()
{
return $this->belongsTo(Diskon::class, 'diskon_id');
}
}
Eager load the diskon relation, it will also help prevent the N+1 issue.
public function index()
{
$daftar_pelanggan = DaftarPelanggan::with('diskon')->get();
$diskons = Diskon::all();
//Since $diskons is required for selects where in only id and nama_member is required
//You can select the two columns only to save on memory
$diskons = Diskon::select('id', 'nama_member')->get();
return view('pages.daftar_pelanggan',compact('daftar_pelanggan','diskons'));
}
To avoid getting error when a relation/related model does not exist, when displaying the related model's in a loop in blade, we can define the relation with a default
public function diskon(){
return $this->belongsTo(Diskon::class,'diskon_id')->withDefault([
'nama_member' => 'Guest',
]);
}

Clear data in modal when clicking close in Laravel

I have a modal (Bootstrap) for creating a new product. When I click the "close" button, which creates a new product, the old data still does not clear from the modal.
My code:
<div class="modal fade" id="product" role="dialog" aria-hidden="true" data-target="#myModal" data-backdrop="static" data-keyboard="false" >
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Create new product</h4>
</div>
<div class="modal-body">
<form role="form" action="{{ route('admin.product.addProduct')}}" method="post" id="frmProduct">
{{ csrf_field() }}
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="">Product Name</label>
<input type="text" class="form-control" id="" name="product_name">
</div>
<div class="form-group">
<label for="">Product Type</label>
<input type="text" class="form-control" id="" name="product_type_id">
</div>
<div class="form-group">
<label for="">Price</label>
<input type="text" class="form-control" id="" name="price">
</div>
<div class="form-group">
<label for="">Status</label>
<select class="form-control input-sm m-bot15" id="" name="status">
<option value="0">Inactive</option>
<option value="1">Active</option>
</select>
</div>
<div class="form-group">
<label for="img">Image</label>
<div class="input-group">
<span class="input-group-btn">
<span class="btn btn-default btn-file">
Choose <input type="file" id="imgInp">
</span>
</span>
<input type="text" class="form-control" name="product_image" readonly>
</div>
<img id='img-upload' class="image_responsive" />
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="">Description</label>
<textarea class="form-control" id="" name="description"></textarea>
</div>
<div class="form-group">
<label for="">Note</label>
<textarea class="form-control" id="" name="addition_information"></textarea>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<input type="submit" value="Save" class="btn btn-success">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</form>
</div>
</div>
</div>
How can I clear the data when closing the modal?
You can add event listener to your close button by adding an id to your close button for example id=close-btn:
document.getElementById("close-btn").addEventListener("click", function(){
document.getElementById("frmProduct").reset();
});
You can use hidden.bs.modal event:
This event is fired when the modal has finished being hidden from the user (will wait for CSS transitions to complete).
The snippet:
$('#product').on('hidden.bs.modal', function(e) {
$(this).find('form').trigger('reset');
})
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#product">
Launch modal
</button>
<div class="modal fade" id="product" role="dialog" aria-hidden="true" data-target="#myModal" data-backdrop="static" data-keyboard="false" >
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Create new product</h4>
</div>
<div class="modal-body">
<form role="form" action="{{ route('admin.product.addProduct')}}" method="post" id="frmProduct">
{{ csrf_field() }}
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="">Product Name</label>
<input type="text" class="form-control" id="" name="product_name">
</div>
<div class="form-group">
<label for="">Product Type</label>
<input type="text" class="form-control" id="" name="product_type_id">
</div>
<div class="form-group">
<label for="">Price</label>
<input type="text" class="form-control" id="" name="price">
</div>
<div class="form-group">
<label for="">Status</label>
<select class="form-control input-sm m-bot15" id="" name="status">
<option value="0">Inactive</option>
<option value="1">Active</option>
</select>
</div>
<div class="form-group">
<label for="img">Image</label>
<div class="input-group">
<span class="input-group-btn">
<span class="btn btn-default btn-file">
Choose <input type="file" id="imgInp">
</span>
</span>
<input type="text" class="form-control" name="product_image" readonly>
</div>
<img id='img-upload' class="image_responsive" />
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="">Description</label>
<textarea class="form-control" id="" name="description"></textarea>
</div>
<div class="form-group">
<label for="">Note</label>
<textarea class="form-control" id="" name="addition_information"></textarea>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<input type="submit" value="Save" class="btn btn-success">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</form>
</div>
</div>
</div>

NotFoundHttpException in RouteCollection.php line 161: laravel 5.2

I created one table in one page, to that table fetching data from database. Then give dynamic buttons for delete and Edit/View. When i click on Delete , it will delete corresponding row from database. Previously it was working properly. But now it showing error "NotFoundHttpException in RouteCollection.php line 161:". Can anyone tell what wrong i did in my code?
My vehicleController.php
<?php
namespace App\Http\Controllers;
use Mail;
use Illuminate\Support\Facades\DB;
use App\Device;
use App\Account;
use App\Http\Requests\createUserRequest;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Input;
use Illuminate\Pagination\Paginator;
class VehicleController extends Controller
{
public $type = 'Device';
public function getIndex()
{
$devices = DB::table('device')->simplePaginate(15);
return view('vehicle.vehicleAdmin')->with('devices', $devices);
}
public function vehicleInsert()
{
$postUser = Input::all();
//insert data into mysql table
$account = Account::select('accountID')->get();
foreach ($account as $acc) {
$abc = $acc->accountID;
}
$data = array("accountID" => $abc,
"vehicleID"=> $postUser['vehicleID']
);
// echo print_r($data);
$ck = 0;
$ck = DB::table('device')->Insert($data);
//echo "Record Added Successfully!";
$devices = DB::table('device')->simplePaginate(50);
return view('vehicle.vehicleAdmin')->with('devices', $devices);
}
public function delete($id)
{
DB::table('device')->where('vehicleID', '=', $id)->delete();
return redirect('vehicleAdmin');
}
public function edit($id)
{
try {
//Find the user object from model if it exists
$devices = DB::table('device')->where('vehicleID', '=', $id)->get();
//$user = User::findOrFail($id);
//Redirect to edit user form with the user info found above.
return view('vehicle.add')->with('devices', $devices);
} catch (ModelNotFoundException $err) {
//redirect to your error page
}
}
}
my vehicleAdmin.blade,php
#extends('app')
#section('content')
<div class="templatemo-content-wrapper">
<div class="templatemo-content">
<ol class="breadcrumb">
<li><font color="green">Home</font></li>
<li class="active">Vehicle information</li>
</ol>
<h1>View/Edit Vehicle information</h1>
<p></p>
<div class="row">
<div class="col-md-12">
<div class="table-responsive" style="overflow-x:auto;">
<table id="example" class="table table-striped table-hover table-bordered" bgcolor="#fff8dc">
<h3>Select a Vehicle :</h3>
<thead>
<tr>
<th>Vehicle ID</th>
<th>Unique ID</th>
<th>Description</th>
<th>Equipment Type</th>
<th>SIM Phone</th>
<th>Server ID</th>
<th>Ignition State</th>
<th>Expecting ACK</th>
<th>Active</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
#foreach($devices as $device)
<tr>
<td>{{ $device->vehicleID }}</td>
<td>{{ $device->uniqueID }}</td>
<td>{{ $device->description }}</td>
<td>{{ $device->equipmentType }}</td>
<td>{{ $device->simPhoneNumber }}</td>
<td></td>
<td>
#if(#$device->ignitionIndex == '0')
OFF
#else
ON
#endif
</td>
<td>{{ $device->expectAck }}</td>
<td>
#if($device->isActive == '1')
Yes
#else
No
#endif
</td>
<td>
<div class="btn-group">
<button type="button" class="btn btn-info">Action</button>
<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu" role="menu">
<li>
View/ Edit
</li>
<li>Delete</li>
</ul>
</div>
</td>
</tr>
#endforeach
</tbody>
</table>
{{--{!! $results->appends(['sort' => $sort])->render() !!}--}}
{{$devices->links()}}
</div>
</div>
</div>
</div>
</div>
{{--{!! $device->links()!!}--}}
</br>
<h4>Create a new Vehicle</h4>
<form role="form" method="POST" action="{{ url('vehicleAdmin') }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="row">
<div class="col-md-6 margin-bottom-15">
<input type="text" class="form-control" name="vehicleID" value="{{ old('vehicleID') }}" placeholder="Enter vehicle ID">
</div>
<div class="row templatemo-form-buttons">
<div class="submit-button">
<button type="submit" class="btn btn-primary">New</button>
</div>
</div>
</div>
</form>
<script type="text/javascript">
$(document).ready(function() {
$('#example').dataTable();
} );
</script>
#endsection
Edit page add.blade.php
#extends('app')
#section('content')
<div class="templatemo-content-wrapper">
<div class="container">
<ol class="breadcrumb">
<li><font color="green">Home</font></li>
<li class="active">View/Edit Vehicle</li>
</ol>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-success">
<div class="panel-heading">View/Edit Vehicle Information</div>
<div class="panel-body">
#if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<form class="form-horizontal" role="form" method="POST" action="{{ url('vehicle/update/') }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
#foreach($devices as $device)
<div class="form-group">
<label class="col-md-4 control-label">Vehicle ID</label>
<div class="col-md-6">
<input type="text" class="form-control" name="vehicleID" value="{{ ($device->vehicleID)}}" placeholder="Enter User ID">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Creation date</label>
<div class="col-md-6">
<input type="text" class="form-control" name="creationTime" value="{{ ($device->creationTime)}}">
</div>
</div>
<!--<div class="form-group">
<label class="col-md-4 control-label">Server ID</label>
<div class="col-md-6">
<input type="text" class="form-control" name="userID" value="{{ ($device->userID)}}" placeholder="Enter User ID">
</div>
</div> -->
<div class="form-group">
<label class="col-md-4 control-label">Unique ID</label>
<div class="col-md-6">
<input type="text" class="form-control" name="uniqueID" value="{{ ($device->uniqueID)}}" placeholder="Enter Unique ID">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Active</label>
<div class="col-md-6">
<select class="form-control" value="{{ ($device->isActive) }}" name="isActive" >
<option value="1">Yes</option>
<option value="0">No</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Vehicle Description</label>
<div class="col-md-6">
<input type="text" class="form-control" name="description" value="{{ ($device->description) }}" placeholder="Enter the description">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Short Name</label>
<div class="col-md-6">
<input type="text" class="form-control" name="displayName" value="{{ ($device->displayName) }}" placeholder="Enter Contact Name">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Vehicle ID</label>
<div class="col-md-6">
<input type="text" class="form-control" name="vehicleID" value="{{ ($device->vehicleID) }}" placeholder="Enter Vehicle ID">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">License Plate</label>
<div class="col-md-6">
<input type="text" class="form-control" name="licensePlate" value="{{ ($device->licensePlate) }}" placeholder="Enter license Plate">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">License Expiration</label>
<div class="col-md-6">
<input type="text" class="form-control" name="licenseExpire" value="{{ ($device->licenseExpire) }}" placeholder="Enter license Expire Date">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Equipment Type</label>
<div class="col-md-6">
<input type="email" class="form-control" name="equipmentType" value="{{ ($device->equipmentType) }}" placeholder="Enter E-Mail Address">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Equipment Status</label>
<div class="col-md-6">
<select class="form-control" value="{{ ($device->equipmentStatus) }}" name="equipmentStatus" >
<option value="0">In Service</option>
<option value="#">Rented</option>
<option value="#">Pending</option>
<option value="#">Completed</option>
<option value="#">Available</option>
<option value="#">Unavailable</option>
<option value="#">Repair</option>
<option value="#">Retired</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">IMEI/EDN Number</label>
<div class="col-md-6">
<input type="email" class="form-control" name="notifyEmail" value="{{ ($device->imeiNumber) }}" placeholder="Enter IMEI/EDN Number">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Serial Number</label>
<div class="col-md-6">
<input type="email" class="form-control" name="notifyEmail" value="{{ ($device->serialNumber) }}" placeholder="Enter Serial Number">
</div>
</div>
<!-- <div class="form-group">
<label class="col-md-4 control-label">Data Key</label>
<div class="col-md-6">
<input type="email" class="form-control" name="notifyEmail" value="{{ ($device->notifyEmail) }}" placeholder="Enter E-Mail Address">
</div>
</div> -->
<div class="form-group">
<label class="col-md-4 control-label">SIM Phone</label>
<div class="col-md-6">
<input type="email" class="form-control" name="notifyEmail" value="{{ ($device->simPhoneNumber) }}" placeholder="Enter SIM Phone Number">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">SMS Email Address</label>
<div class="col-md-6">
<input type="email" class="form-control" name="notifyEmail" value="{{ ($device->smsEmail) }}" placeholder="Enter SMS E-Mail Address">
</div>
</div>
<!-- <div class="form-group">
<label class="col-md-4 control-label">Group Pushpin ID</label>
<div class="col-md-6">
<input type="email" class="form-control" name="notifyEmail" value="{{ ($device->notifyEmail) }}" placeholder="Enter E-Mail Address">
</div>
</div> -->
<div class="form-group">
<label class="col-md-4 control-label">Map Route Color</label>
<div class="col-md-6">
<select class="form-control" value="{{ ($device->timeZone) }}" name="timeZone" >
<option value="0">Black</option>
<option value="#">Brown</option>
<option value="#">Red</option>
<option value="#">Orange</option>
<option value="#">Green</option>
<option value="#">Blue</option>
<option value="#">Purple</option>
<option value="#">Grey</option>
<option value="#">Cyan</option>
<option value="#">Pink</option>
<option value="#">None</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Fuel Capacity</label>
<div class="col-md-6">
<input type="email" class="form-control" name="fuelCapacity" value="{{ ($device->fuelCapacity) }}" >
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Driver ID</label>
<div class="col-md-6">
<input type="email" class="form-control" name="driverID" value="{{ ($device->driverID) }}">
</div>
</div>
<!-- <div class="form-group">
<label class="col-md-4 control-label">Reported Odometer</label>
<div class="col-md-6">
<input type="email" class="form-control" name="notifyEmail" value="{{ old('notifyEmail') }}" placeholder="Enter E-Mail Address">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Reported Engine Hours</label>
<div class="col-md-6">
<input type="email" class="form-control" name="notifyEmail" value="{{ old('notifyEmail') }}" placeholder="Enter E-Mail Address">
</div>
</div> -->
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-warning">
Save
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
#endsection
Routes.php
Route::any('vehicleAdmin', 'VehicleController#getIndex');
Route::post('vehicleAdmin', 'VehicleController#vehicleInsert');
Route::get('vehicle/edit/{id}', 'VehicleController#edit');
Route::delete('vehicle/delete/{id}', 'VehicleController#delete');
I think when you click the link, it is probably sending a GET request to that end point unless you set the method to delete in ajax call,. CRUD in Laravel works according to REST. This means it is expecting a DELETE request instead of GET.
So I would suggest you to make your route as follow
Route::get('/vehicle/delete/{id}', 'VehicleController#delete');

Categories