天天看點

laravel-admin 記錄關聯關系Scaffold 報錯Scaffold報錯擷取目前id圖檔上傳

關聯關系

*  一對一
	```php
		 // 主鍵在A中,A模型代碼:
		public function user() {
			return $this->belongsTo('App\Models\User', 'user_id', 'id');
	    }
	    // A的控制器中,注意: 外鍵user_id
	     $form->select('user_id', '使用者')->options(User::all()->pluck('name', 'id'))->rules('required');
	 ```
           
  • 編輯頁面->rules(‘required’)失效,已上傳的圖檔還提示 請選擇一個檔案,版本1.6.12
    • 版本bug,回退到1.6.11版本正常 composer require encore/laravel-admin:1.6.11

Scaffold 報錯

> file_put_contents(D:\GitHub\growth\app\Models/test.php): failed to open stream: No such file or directory
> 解決: 在app下建立Models檔案夾
           
  • 顯示頁面點switch開關沒儲存成功
    // 需要在 form() 方法中添加相應的的列
    $form->switch('state', '處理狀态')
            ->states([
                'on'  => ['value' => 1, 'text' => '已處理', 'color' => 'success'],
                'off' => ['value' => 0, 'text' => '未處理', 'color' => 'default'],
            ])
            ->default(0);
               

Scaffold報錯

> ArgumentCountError In MigrationCreator.php line 40 :
Too few arguments to function Illuminate\Database\Migrations\MigrationCreator::__construct(), 1 passed in /Users/zwl/Codes/laravel/amiao/vendor/laravel-admin-ext/helpers/src/Controllers/ScaffoldController.php on line 65 and exactly 2 expected
>解決:  https://github.com/laravel-admin-extensions/helpers/issues/29
           

擷取目前id

$arr = request()->route()->parameters();
$id = $arr['your model'];
// 或者
$id = $form->model()->id;

           

圖檔上傳

// fisystemsphp
disks' => [
    ... ,

    'admin' => [
        'driver' => 'local',
        'root' => public_path('uploads'),
        'visibility' => 'public',
        'url' => env('APP_URL').'/uploads',
    ],
],

// .env
APP_URL= http://xxxx  // 不加http圖檔加載不了。