2016-07-25 6 views
0

데이터베이스에서 데이터를 가져 오는 한 테이블에서 하나의 테이블을 생성했습니다. 그런 다음 삭제 및 편집 /보기를위한 동적 버튼을 제공하십시오. 삭제를 클릭하면 해당 행이 데이터베이스에서 삭제됩니다. 이전에는 제대로 작동했습니다. 하지만 이제는 "RouteCollection.php line 161 : NotFoundHttpException 오류"가 표시됩니다. 아무도 내 코드에서 내가 뭘 잘못했는지 말할 수 있습니까?RouteCollection.php의 NotFoundHttpException 라인 161 : laravel 5.2

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

내 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 

편집 페이지 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

이 노선 : 모든 후 시도하십시오 경로를 삭제하고 쓰기 시도에 따라 당신이 경로를 만들기 위해 제안 ... 나는이이 작업 .... 감사합니다 친구 지금 –

답변

0

링크를 클릭하면 AJAX 호출에서 삭제할 메서드를 설정하지 않으면 해당 끝점에 GET 요청을 보내는 것 같습니다. Laravel의 CRUD는 REST에 따라 작동합니다. 이는 GET 대신 DELETE 요청을 기다리고 있음을 의미합니다. 그래서 내가

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

일을해야한다고 생각 –