0

我不知道为什么我得到一张空桌子。过去,它对我有用,但为什么我现在得到这个?我做错了什么?

控制器: AdminServiceController

public function create()
{
    return view("admin.service.create");
}

public function store(Request $request)
{
    $date = $this->vvalidate($request);
    $data['creator'] = auth()->user()->id;
    Services::create($data);
}

private function vvalidate($request)
{
    $rules = [
        'title' => 'required|unique:services',
        'description' => 'required|min:100',
    ];
    
    return $this->validate($request, $rules);
}

型号: Services.php

class Services extends Model
{
    use HasFactory;
    
    protected $guarded = [];
}

路由: web.php

Route::prefix('admin')->group(function () {
    Route::name('admin.')->group(function () {
        Route::middleware('auth')->group(function () {
            Route::get('/', function () {
                return view('admin');
            });
            Route::resource('service', 'App\Http\Controllers\AdminServiceController');
        });
    });
});
4

1 回答 1

0

管理服务控制器

  public function store(Request $request)
  { 
    Services::create($this->vvalidate($request));
  }

  private function vvalidate($request)
  {
    $data = $request->validate([
        'title' => 'required|unique:services',
        'description' => 'required|min:100',
    ]);
    $data['creator'] = auth()->user()->id;
    return $data;
  }

服务.php

 protected $fillable = [
   'title', 'description'
];
于 2020-09-24T06:09:02.453 回答