0
したがって、Framework Laravel 5.3でWebアプリケーションを開発するには、laravel-backpackとphp ver 5.6.30を使用する必要があります。私は私のアプリの分野でAJAXから使用フィールドタイプSELECT2をしようとしていたが、私は自分のコードを言ったエラーが90Framework Laravel 5.3 for PHP ver 5.6.30でバックパックフィールドタイプを使用するAjaxから選択
4bb1a9dc582e785d21cadb68014f51787068f3ed.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\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;
}
}
コードは失敗しますが失敗します。そして最終的にここであなた達の助けを得ようとしています。ご清聴ありがとうございました。
までは利用できません「ヌル合体」演算子
??
を使用しています。それは動作しません。 – Ohgodwhyそれは良い習慣ではありませんが、エラーを投げるべきではありません。これが起こる場所を私たちに見せてください。これはキャッシュされたビューをコンパイルし、元のビューを見つけます。 '$ field ['value']の行に沿って何かしていますか?古い($ field ['name'])?? 0 'とする。 php5.6の構文が間違っています – devk