laravel-admin 记录

嵇出野
2023-12-01

关联关系

*  一对一
	```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图片加载不了。

 类似资料: