我是Laravel新手,根據我與iis和sql server的連接,我有幾個問題。揹包Laravel與他和SQL Server的問題
首先我從刪除CrudTable有405錯誤。我想這是一個iis錯誤,但我在這裏問,以防有人知道如何解決這個問題。
我的另一個問題是,我無法在1到多個關係中顯示值而不是外部表的ID。
我得到一個空列,在創建刀片時,我選擇一個特定的值,系統在該列上插入一個零。
下面你可以看到我的代碼。
table book_code
{
code varchar(15) PK,
title varchar(50)
}
bookcodes型號
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Backpack\CRUD\CrudTrait;
class bookcodes extends Model
{
use CrudTrait;
protected $table = 'book_codes';
protected $primaryKey = 'code';
protected $fillable = ['title'];
public function rest_declaration()
{
return $this->hasMany('App\Models\rest_declaration');
}
}
bookcodes控制器無關
table rest_declaration
{
id int,
date1 date,
date2 date,
code //the foreign of bookcodes
}
rest_declaration型號
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Backpack\CRUD\CrudTrait;
use DB;
class rest_declaration extends Model
{
use CrudTrait;
protected $table = 'rest_declaration';
protected $primaryKey = 'aa'; //is my id
protected $fillable = ['aa', 'code', 'date1', 'date2'];
public function bookcodes()
{
return $this->belongsTo('App\Models\bookcodes');
}
}
rest_declaration控制器
<?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\rest_declarationRequest as StoreRequest;
use App\Http\Requests\rest_declarationRequest as UpdateRequest;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class rest_declarationCrudController extends CrudController
{
public function setup()
{
parent::__construct();
/*
|--------------------------------------------------------------------------
| BASIC CRUD INFORMATION
|--------------------------------------------------------------------------
*/
$this->crud->setModel('App\Models\rest_declaration');
$this->crud->setRoute(config('backpack.base.route_prefix') . '/restdeclaration');
$this->crud->setEntityNameStrings('rest declaration', 'rest declaration');
$this->crud->setDefaultPageLength(10);
$this->crud->allowAccess('show');
$this->crud->addClause('where', 'code', '=', Auth::user()->name);
$this->crud->allowAccess('details_row');
$this->crud->enableAjaxTable();
$this->crud->enableExportButtons();
//Fields for Create and Edit Forms
$this->crud->addField([ // SELECT
'label' => 'AA',
'type' => 'text',
'name' => 'aa1',
'value' => $this->getmaxaa(),
'attributes' =>
['disabled' => 'disabled',],
]);
$this->crud->addField([ // SELECT
'label' => 'AA',
'type' => 'hidden',
'name' => 'aa',
'value' => $this->getmaxaa(),
]);
$this->crud->addField([ // SELECT
'label' => 'BookCode',
//'type' => 'select',
'name' => 'code',
'entity' => 'bookcodes',
'attribute' => 'title',
'model' => 'App\Models\bookcodes',
]);
$this->crud->addField([ // Date
'name' => 'date1',
'label' => 'From',
'type' => 'date_picker',
// optional:
'date_picker_options' => [
'todayBtn' => false,
'format' => 'dd-mm-yyyy',
'language' => 'en',
'autoclose' => true,
'showOnFocus' => false,
],
]);
$this->crud->addField([ // Date
'name' => 'date2',
'label' => 'To',
'type' => 'date_picker',
// optional:
'date_picker_options' => [
'todayBtn' => false,
'format' => 'dd-mm-yyyy',
'language' => 'en',
'autoclose' => true,
'showOnFocus' => true,
],
]);
$this->crud->addColumn([
'label' => 'Άδεια',
'type' => 'select',
'name' => 'code',
'entity' => 'bookcodes',
'attribute' => 'title',
'model' => 'App\Models\bookcodes',
]);
$this->crud->addColumn([
'name' => 'date1',
'label' => 'From',
'type' => 'date',
'date_picker_options' => [
'todayBtn' => false,
'format' => 'dd-mm-yyyy',
'language' => 'en',],
]);
$this->crud->addColumn([
'name' => 'date2',
'label' => 'To',
'type' => 'date',
'date_picker_options' => [
'todayBtn' => false,
'format' => 'dd-mm-yyyy',
'language' => 'en',],
]);
}
public function store(StoreRequest $request)
{
$redirect_location = parent::storeCrud($request);
return $redirect_location;
}
public function update(UpdateRequest $request)
{
$redirect_location = parent::updateCrud($request);
return $redirect_location;
}
public function getmaxaa()
{
$max = 'App\Models\AitisiAdeias'::max('aa');
$max = $max + 1;
return $max;
}
}
我在做什麼錯?
你能幫我嗎?
對不起,我的延遲答案。我已經嘗試過,沒有運氣。我用一個從外部表中檢索列表的函數修復了這個問題,但我知道這不是正確的方法。也許問題是主鍵是nvarchar而不是int。 – maryxis