Vehicle.php(app \ Vehicle.php文件)
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Vehicle;
class VehicleController extends Controller
{
public function index()
{
$vehicles = Vehicle::all();
return response()->json(['data'=> $vehicles], 200);
}
}
VehicleController.php
| Domain | Method | URI | Name | Action
| Middleware |
+--------+-----------+-----------------------------------+------------------------+-------------------------------------
-----------------+------------+
| | GET|HEAD | makers | makers.index | App\Http\Controllers\MakerController
@index | web |
| | POST | makers | makers.store | App\Http\Controllers\MakerController
@store | web |
| | PUT|PATCH | makers/{makers} | makers.update | App\Http\Controllers\MakerController
@update | web |
| | DELETE | makers/{makers} | makers.destroy | App\Http\Controllers\MakerController
@destroy | web |
| | GET|HEAD | makers/{makers} | makers.show | App\Http\Controllers\MakerController
@show | web |
| | POST | makers/{makers}/vehicle | makers.vehicle.store | App\Http\Controllers\MakersVehicleCo
ntroller@store | web |
| | GET|HEAD | makers/{makers}/vehicle | makers.vehicle.index | App\Http\Controllers\MakersVehicleCo
ntroller@index | web |
| | PUT|PATCH | makers/{makers}/vehicle/{vehicle} | makers.vehicle.update | App\Http\Controllers\MakersVehicleCo
ntroller@update | web |
| | GET|HEAD | makers/{makers}/vehicle/{vehicle} | makers.vehicle.show | App\Http\Controllers\MakersVehicleCo
ntroller@show | web |
| | DELETE | makers/{makers}/vehicle/{vehicle} | makers.vehicle.destroy | App\Http\Controllers\MakersVehicleCo
ntroller@destroy | web |
| | GET|HEAD | vehicles | vehicles.index | App\Http\Controllers\VehicleControll
er@index | web |
+--------+-----------+-----------------------------------+------------------------+-------------------------------------
以下是我的路线列表
$.ajax({
type: "GET",
url: http://siteurl.com/wp-admin/admin-ajax.php?action=send_mail,
data:{
'fn':'send_mail'
},
success:function(data){
}
});
当我打电话给myapp.com/vehicles时,它会告诉我“Class&#39; App \ Vehicle&#39;找不到&#39;错误。我还有Maker控制器和Maker模型。我可以致电myapp.com/makers,它也会正常返回。请指出我的弱点在哪里。
答案 0 :(得分:0)
您将班级Vehicles
命名为Vehicle
。您应该将其命名为Vehicle
,确保它为Vehicle.php
,您就可以了。
该关系也应该包含完全合格的类名:
public function maker()
{
return $this->belongsTo('App\Maker');
// or
return $this->belongsTo(Maker::class);
// assuming they are in the same namespace
}