RouteCollection.php第161行中的NotFoundHttpException:laravel 5.2

时间:2016-07-25 06:28:48

标签: php mysqli laravel-5.2

我在一个页面中创建了一个表,从该表中获取数据库中的数据。然后为删除和编辑/查看提供动态按钮。当我单击Delete时,它将从数据库中删除相应的行。以前它工作正常。但现在它在RouteCollection.php第161行显示错误" NotFoundHttpException:"。任何人都可以告诉我在我的代码中做了什么错误吗?

我的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', 'VehicleController@getIndex');
Route::post('vehicleAdmin', 'VehicleController@vehicleInsert');
Route::get('vehicle/edit/{id}', 'VehicleController@edit');
Route::delete('vehicle/delete/{id}', 'VehicleController@delete');

1 个答案:

答案 0 :(得分:0)

我认为当您单击该链接时,除非您在ajax调用中将方法设置为delete,否则它可能会向该端点发送GET请求。 Laravel中的CRUD根据REST工作。这意味着它期待DELETE请求而不是GET。 所以我建议你按照以下方式制定路线

Route::get('/vehicle/delete/{id}', 'VehicleController@delete');