我按照本教程设置了一个 CRUD 示例。但我无法让它工作,我不知道为什么。这是我的代码
SomeitemCrudController.php
<?php
namespace App\Http\Controllers\Admin;
use Backpack\CRUD\app\Http\Controllers\CrudController;
// VALIDATION: change the requests to match your own file names if you need form validation
use App\Http\Requests\SomeitemRequest as StoreRequest;
use App\Http\Requests\SomeitemRequest as UpdateRequest;
class SomeitemCrudController extends CrudController
{
public function setUp()
{
/*
|--------------------------------------------------------------------------
| BASIC CRUD INFORMATION
|--------------------------------------------------------------------------
*/
$this->crud->setModel("App\Models\Someitem");
$this->crud->setRoute("admin/someitem");
$this->crud->setEntityNameStrings('someitem', 'someitems');
/*
|--------------------------------------------------------------------------
| BASIC CRUD INFORMATION
|--------------------------------------------------------------------------
*/
$this->crud->setFromDb();
// $this->crud->setColumns(['nama']);
$this->crud->addField([
'nama' => 'Nama',
'keterangan' => 'Keterangan',
'harga' => 'Harga'
]);
}
public function store(StoreRequest $request)
{
$redirect_location = parent::storeCrud();
return $redirect_location;
}
public function update(UpdateRequest $request)
{
$redirect_location = parent::updateCrud();
return $redirect_location;
}
}
模型,Someitem.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Backpack\CRUD\CrudTrait;
class SomeItem extends Model
{
use CrudTrait;
//
protected $table = 'someitem';
protected $fillable = ['nama', 'keterangan', 'harga'];
public $timestamps = true;
}
请求,SomeitemRequest.php
<?php
namespace App\Http\Requests;
use App\Http\Requests\Request;
class SomeitemRequest extends \Backpack\CRUD\app\Http\Requests\CrudRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return \Auth::check();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
// 'name' => 'required|min:5|max:255'
];
}
/**
* Get the validation attributes that apply to the request.
*
* @return array
*/
public function attributes()
{
return [
//
];
}
/**
* Get the validation messages that apply to the request.
*
* @return array
*/
public function messages()
{
return [
//
];
}
}
然后,路线
<?php
Route::group([
'prefix' => config('backpack.base.route_prefix', 'admin'),
'middleware' => ['admin'],
'namespace' => 'Admin'
], function() {
CRUD::resource('pelayanan', 'Admin\PelayananCrudController');
Route::get('/test', function () {
return view('welcome');
});
});
我可以访问http://localhost/myapp/public/admin/test
成功,但我无法访问http://localhost/myapp/public/admin/someitem
,它总是返回错误500
我是 laravel (和 PHP)的新手,任何帮助表示赞赏。谢谢!