簡體   English   中英

使用背包字段類型從ajax選擇,使用PHP版本5.6.30的Framework Laravel 5.3發行了

[英]Got Issue for Framework Laravel 5.3 with PHP ver 5.6.30 using backpack field type Select from ajax

因此,我使用Framework Laravel 5.3開發的Web應用程序包括laravel-backpack並使用php ver 5.6.30。 我試圖在我的應用程序字段中使用Ajax中的字段類型select2,但出現錯誤,提示我的代碼在4bb1a9dc582e785d21cadb68014f51787068f3ed.php第90行上出現語法錯誤。

錯誤信息

然后我看一下文件:

錯誤

我的控制器是:

<?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 7之前不可用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM