2017-10-09 80 views
1

我是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; 
    } 

} 

我在做什麼錯?

你能幫我嗎?

回答

0

我發現,根據與刪除功能的問題的解決方案。

我沒有使用任何路線::等問題是我的iis。我在IIS中的Handler Mapping內部創建了一個新映射,並選擇了用於我的應用程序的PHP版本。然後,我在第三個選項卡中選擇了所有動詞和腳本值。

And ... Voila ..現在刪除工作就像一個魅力!

關係問題依然存在。 我意識到,改變如下:

$this->crud->addColumn([ 
      'label'      => 'BookCode', 
      'type'      => 'select', 
      'name'      => 'code', 
      'entity'     => 'bookcodes', 
      'attribute'     => 'title', 
      'model'      => 'App\Models\bookcodes', 
     ]); 

$this->crud->addColumn([ 
      'label'      => 'BookCode', 
      'type'      => 'select2', 
      'name'      => 'code', 
      'entity'     => 'bookcodes', 
      'attribute'     => 'title', 
      'model'      => 'App\Models\bookcodes', 
     ]); 

我得到的代碼,並沒有任何更多的空列。但仍然需要獲得標題而不是代碼。

任何幫助將不勝感激!

0

爲405錯誤我認爲你使用的是錯誤的路由類型,你正在發送請求,但路由聲明爲get.try Route :: any,看看它是否能解決問題!

對於第二個問題,您的命名空間是不正確

嘗試「應用程序\ rest_declaration」

0

在你的模型,你還需要通過列連接

public function bookcodes() 
{ 
    return $this->belongsTo('App\Models\bookcodes', 'code'); 
} 
+0

對不起,我的延遲答案。我已經嘗試過,沒有運氣。我用一個從外部表中檢索列表的函數修復了這個問題,但我知道這不是正確的方法。也許問題是主鍵是nvarchar而不是int。 – maryxis