我对独特验证laravel有一些问题
<?php
namespace Amodules\Hmastermedis\Http\Controllers;
use Illuminate\Http\Request;
use Amodules\Hmastermedis\Models\Dokter;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Theme;
use Amodules\Hmastermedis\Models\Spesialisasi;
use Yajra\Datatables\Facades\Datatables;
use DB;
use Session;
use validate;
class DokterController extends Controller
{
public function store(Request $request)
{
$this->validate($request, [
'dr_cd' => 'required|unique:Dokter',
'dr_nm' => 'required',
]);
$dokter = new Dokter();
$dokter->dr_cd=$request->dr_cd;
$dokter->dr_nm=$request->dr_nm;
$dokter->spesialis_cd=$request->spesialis_cd;
$dokter->save();
Session::flash('dokter', 'Dokter berhasil di tambahkan');
return redirect('hmastermedis/dokter');
}
}
这是我的模特
<?php
namespace Amodules\Hmastermedis\Models;
use Illuminate\Database\Eloquent\Model;
/**
*
*/
class Dokter extends Model
{
public $primarykey = 'dr_cd';
public $incrementing = false;
protected $fillable = ['dr_cd','dr_cm','spesialis_cd','paramedis_tp'];
protected $table = 'trx_dokter';
public $timestamps = false;
public function spesialisasi()
{
return $this->hasOne('Amodules\Hmastermedis\Models\Spesialisasi','spesialis_cd','spesialis_cd');
}
}
但是当我运行我的代码时,类dokter不存在
哎呀,好像出了什么问题。 IlluminateRegistry.php第334行中的1/1 ReflectionException:类Dokter不存在in IlluminateRegistry.php line 334
at ReflectionClass->__construct('Dokter') in IlluminateRegistry.php line 334
at IlluminateRegistry->getManagerForClass('Dokter') in DoctrinePresenceVerifier.php line 123
at DoctrinePresenceVerifier->getEntityManager('Dokter') in DoctrinePresenceVerifier.php line 92
at DoctrinePresenceVerifier->select('Dokter') in DoctrinePresenceVerifier.php line 45
at DoctrinePresenceVerifier->getCount('Dokter', 'dr_cd', 'df', null, null, array()) in Validator.php line 1426
at Validator->validateUnique('dr_cd', 'df', array('Dokter'), object(Validator)) in Validator.php line 545
at Validator->validateAttribute('dr_cd', 'unique:Dokter') in Validator.php line 461
at Validator->passes() in Validator.php line 486
at Validator->fails() in ValidatesRequests.php line 54
at Controller->validate(object(Request), array('dr_cd' => 'required|unique:Dokter', 'dr_nm' => 'required')) in DokterController.php line 60
at DokterController->store(object(Request))
at call_user_func_array(array(object(DokterController), 'store'), array(object(Request))) in Controller.php line 55
at Controller->callAction('store', array(object(Request))) in ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch(object(Route), object(DokterController), 'store') in Route.php line 190
at Route->runController() in Route.php line 144
at Route->run(object(Request)) in Router.php line 642
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 64
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Router.php line 644
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 618
at Router->dispatchToRoute(object(Request)) in Router.php line 596
at Router->dispatch(object(Request)) in Kernel.php line 267
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 54
at require_once('D:\xampp\htdocs\amteklab\AMHES\public\index.php') in server.php line 21
感谢你的帮助
答案 0 :(得分:0)
如果您的模型类是在您调用它之后创建的,则需要运行composer dump-autoload,以便将Dokter添加到项目的autoload_classmap.php中