Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialdemet Akyol
42 PointsClass validator does not exist
I am trying to write test code for function in my service.I get the error I don't understand when I run the test code My test code is;
public function testAddToCartService()
{
$request = [
'id' => '3880',
'uid' => '1996',
'amount' => '10',
'attid' => '203'
];
$service = new Service();
$actual_result = $service->addToBasket($request);
$expected_result= array(
'status' => true,
'code' => 0,
'message' => 'success',
'data' => [
'ProductId' =>\DB::table('basket')->select('id')->orderBy('id', 'DESC')->first()+1
]
);
$this->assertEquals($expected_result,$actual_result);
}
my service is;
public function addToBasket($data){
// todo validasyon kismini incelemek lazim
$validatedData = Validator::make($data, array(
'id' => 'required',
'uid' => 'required',
'amount' => 'required',
'attid' => 'required',
));
try {
$validatedData->validate();
} catch (\Exception $e){
return array(
'status' => false,
'code' => 9,
'message' => config('exception_codes.9').'<br/>'.$validatedData->errors(),
'data' => []
);
}
try {
$cart = new ModelBasket();
foreach ($data as $key => $val) {
$methodName = "set" . ucfirst($key);
$cart->$methodName($val);
}
$cartProductId = $this->cRepository->addToBasket($cart);
return array(
'status' => true,
'code' => 0,
'message' => 'success',
'data' => [
'cProductId' => $cProductId
]
);
} catch (\Exception $e){
return array(
'status' => false,
'code' => 10,
'message' =>config('exception_codes.10'),
'data' => []
);
}
}
I am getting this error;
Class validator does not exist and class config does not exist
what is wrong?
demet Akyol
42 Pointsdemet Akyol
42 PointsI tried this ; use Validator; app.php file;
'aliases' => ['Config' => Illuminate\Support\Facades\Config::class]
'providers' => [ Illuminate\Validation\ValidationServiceProvider::class]