0
因此,我正在使用Framework Laravel 5.3开发Web应用程序,包括laravel-backpack和使用PHP版本5.6.30。我是从我的应用程序的场阿贾克斯试图使用字段类型选择2,但我得到的错误是说我的代码有4bb1a9dc582e785d21cadb68014f51787068f3ed.php行语法错误90.使用背包字段类型的PHP版本5.6.30得到了框架Laravel 5.3的问题从ajax中选择
然后我看向文件:
我的控制器是:
<?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\Models\Report;
use App\Http\Requests\ReportRequest as StoreRequest;
use App\Http\Requests\ReportRequest as UpdateRequest;
class ReportCrudController extends CrudController
{
public function setUp()
{
/*
|--------------------------------------------------------------------------
| BASIC CRUD INFORMATION
|--------------------------------------------------------------------------
*/
$this->crud->setModel("App\Models\Report");
$this->crud->setRoute("admin/report");
$this->crud->setEntityNameStrings('report', 'reports');
/*
|--------------------------------------------------------------------------
| BASIC CRUD INFORMATION
|--------------------------------------------------------------------------
*/
//$this->crud->setFromDb();
$this->crud->setColumns([
[
'label' => "Student's Name", // Table column heading
'type' => 'select',
'name' => 'student', //-> on Question
'entity' => 'stackStudent', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => 'App\Models\Student', // foreign key model
],
[
'label' => 'Generation', // Table column heading
'type' => 'select',
'name' => 'generation', //-> on Question
'entity' => 'stackGeneration', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => 'App\Models\Generation', // foreign key model
],
[
'label' => 'Semester', // Table column heading
'type' => 'select',
'name' => 'semester', //-> on Question
'entity' => 'stackSemester', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => 'App\Models\Semester', // foreign key model
],
[
'label' => 'Class', // Table column heading
'type' => 'select',
'name' => 'class', //-> on Question
'entity' => 'stackClass', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => 'App\Models\Kelas', // foreign key model
],
[
'label' => 'Department', // Table column heading
'type' => 'select',
'name' => 'department', //-> on Question
'entity' => 'stackDepartment', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => 'App\Models\Department', // foreign key model
],
[
'label' => 'Class Type', // Table column heading
'type' => 'select',
'name' => 'classtype', //-> on Question
'entity' => 'stackClasstype', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => 'App\Models\Classtype', // foreign key model
],
[
'label' => 'Lesson', // Table column heading
'type' => 'select',
'name' => 'lesson', //-> on Question
'entity' => 'stackLesson', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => 'App\Models\Lesson', // foreign key model
],
[
'name' => 'score',
'label' => 'Score',
'type' => 'number',
],
]);
$this->crud->addFields([
/*[
'label' => "Student's Name", // Table column heading
'type' => 'select',
'name' => 'student', //-> on Question
'entity' => 'stackStudent', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => 'App\Models\Student', // foreign key model
],*/
// 1-n relationship
['label' => "Student's Name", // Table column heading
'type' => "select2_from_ajax",
'name' => 'student', // the column that contains the ID of that connected entity
'entity' => 'stackStudent', // the method that defines the relationship in your Model
'attribute' => "name", // foreign key attribute that is shown to user
'model' => "App\Models\Student", // foreign key model
'data_source' => url("api/student"), // url to controller search function (with /{id} should return model)
'placeholder' => "Search a name...", // placeholder for the select
'minimum_input_length' => 2, // minimum characters to type before querying results
'pivit' => true,
],
[
'label' => 'Generation', // Table column heading
'type' => 'select',
'name' => 'generation', //-> on Question
'entity' => 'stackGeneration', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => 'App\Models\Generation', // foreign key model
],
[
'label' => 'Semester', // Table column heading
'type' => 'select',
'name' => 'semester', //-> on Question
'entity' => 'stackSemester', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => 'App\Models\Semester', // foreign key model
],
[
'label' => 'Class', // Table column heading
'type' => 'select',
'name' => 'class', //-> on Question
'entity' => 'stackClass', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => 'App\Models\Kelas', // foreign key model
],
[
'label' => 'Department', // Table column heading
'type' => 'select',
'name' => 'department', //-> on Question
'entity' => 'stackDepartment', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => 'App\Models\Department', // foreign key model
],
[
'label' => 'Class Type', // Table column heading
'type' => 'select',
'name' => 'classtype', //-> on Question
'entity' => 'stackClasstype', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => 'App\Models\Classtype', // foreign key model
],
[
'label' => 'Lesson', // Table column heading
'type' => 'select',
'name' => 'lesson', //-> on Question
'entity' => 'stackLesson', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => 'App\Models\Lesson', // foreign key model
],
[
'name' => 'score',
'label' => 'Score',
'type' => 'number',
],
]);
}
public function store(StoreRequest $request)
{
// your additional operations before save here
$redirect_location = parent::storeCrud();
// your additional operations after save here
// use $this->data['entry'] or $this->crud->entry
return $redirect_location;
}
public function update(UpdateRequest $request)
{
// your additional operations before save here
$redirect_location = parent::updateCrud();
// your additional operations after save here
// use $this->data['entry'] or $this->crud->entry
return $redirect_location;
}
}
我会尽力修复代码但失败。最后,我最终在这里试图从你们那里得到帮助。感谢您的关注。
你试图将PHP代码转换为JavaScript文件。这将无法正常工作。 – Ohgodwhy
尽管不是很好的做法,但它也不应该抛出错误。向我们展示发生这种情况的视图。这是编译的缓存视图,找到原始视图。你正在做'$ field ['value']?旧的($ field ['name'])?? 0'某处。这是不正确的PHP 5.6语法 – devk