2016-07-25 8 views
0

Ich erstellte eine Tabelle auf einer Seite, um die Tabelle Daten aus der Datenbank abrufen. Geben Sie dann dynamische Schaltflächen zum Löschen und Bearbeiten/Anzeigen ein. Wenn ich auf Löschen klicke, wird die entsprechende Zeile aus der Datenbank gelöscht. Zuvor funktionierte es einwandfrei. Aber jetzt zeigt es Fehler "NotFoundHttpException in RouteCollection.php Zeile 161:". Kann mir jemand sagen, was ich falsch in meinem Code gemacht habe?NotFoundHttpException in RouteCollection.php Zeile 161: Laravel 5.2

Mein 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 
     } 
    } 
} 

mein vehicleAdmin.blade, php

@extends('app') 

@section('content') 

<div class="templatemo-content-wrapper"> 
     <div class="templatemo-content"> 
      <ol class="breadcrumb"> 
       <li><a href="{{ url("/") }}"><font color="green">Home</font></a></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> 
               <a href="{{url('/vehicle/edit/'.$device->vehicleID)}}">View/ Edit</a> 
              </li> 

              <li><a href="{{ url('/vehicle/delete/'.$device->vehicleID)}}">Delete</a></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 

Seite bearbeiten add.blade.php

@extends('app') 

@section('content') 

    <div class="templatemo-content-wrapper"> 
     <div class="container"> 
      <ol class="breadcrumb"> 
       <li><a href="{{ url("/") }}"><font color="green">Home</font></a></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', '[email protected]'); 
Route::post('vehicleAdmin', '[email protected]'); 
Route::get('vehicle/edit/{id}', '[email protected]'); 
Route::delete('vehicle/delete/{id}', '[email protected]'); 
+0

versuchen Strecke schreiben :: any nach Route löschen und dann versuchen .. Ich denke, das –

Antwort

0

Ich denke, wenn Sie auf den Link klicken, sendet es wahrscheinlich eine GET-Anforderung an diesen Endpunkt, es sei denn, Sie legen die zu löschende Methode in einem AJAX-Aufruf fest. CRUD in Laravel arbeitet nach REST. Dies bedeutet, dass eine DELETE-Anfrage anstelle von GET erwartet wird. So würde ich vorschlagen, dass Sie Ihren Weg zu machen, wie folgt

Route::get('/vehicle/delete/{id}', '[email protected]'); 
+0

jetzt funktionieren sollte seine Arbeits .... Dank Geck –