use tow locale in php faker at same time - php

im using laravel 7 and im using php faker ..
if i want to seed customer i did this code ..
$factory->define(App\Models\Customer::class, function (Faker $faker) {
return [
'number' => $faker->numberBetween(1,1000000),
'name' => $faker->name,
'foreign_name' => $faker->name,
'financial_account_type_id' => 2,
'address' => $faker->address,
'tax_id' => $faker->numberBetween(1,100000),
'phone' => $faker->e164PhoneNumber,
'mobile' => $faker->e164PhoneNumber,
'email' => $faker->email,
'sales_payment_term_id' => $faker->numberBetween(1,7),
'purchase_payment_term_id' => $faker->numberBetween(1,7),
'note' => $faker->sentence,
];
});
now in my app.php i did this code also ..
'faker_locale' => 'ar_SA',
i want the 'foreign_name' => $faker->name, to be in english language just this line ..
is that possible to change only one line locale ..
thanks ..

Related

Laravel: Factory Fake Car Data

I created a new factory in Laravel called "CarFactory.php" and I want to use https://github.com/pelmered/fake-car.
This is the fake data that I will insert into my database using Tinker:
return [
'name' => $this->faker->vehicleBrand(),
'founded' => $this->faker->biasedNumberBetween(1998,2017, 'sqrt'),
'description' => $this->faker->paragraph()
];
In the Laravel usage code, I'm not sure where to put this (e.g. Car Model, CarFactory):
$faker->addProvider(new \Faker\Provider\Fakecar($faker));
$v = $faker->vehicleArray();
return [
'vehicle_type' => 'car',
'vin' => $faker->vin,
'registration_no' => $faker->vehicleRegistration,
'type' => $faker->vehicleType,
'fuel' => $faker->vehicleFuelType,
'brand' => $v['brand'],
'model' => $v['model'],
'year' => $faker->biasedNumberBetween(1998,2017, 'sqrt'),
];
Help is needed to know how to set this up.

Laravel: Edit value only if it appears in the request?

in my app the user can update the info of stripe connected account, however I ONLY want to actullay update the value of the fields that appear in the request payload, I could do this with a simple if check but the way I update the stripe array method makes this issue more complicated .
Is there any syntax sugar or trick to make this easier.
How my update method looks;
public function editConnectedAccount(Request $request)
{
$account = Account::retrieve($request->connectedAccountId);
Account::update(
$request->connectedAccountId,
[
'type' => 'custom',
'country' => 'ES',
'email' => $request->userEmail,
'business_type' => 'individual',
'tos_acceptance' => [ 'date' => Carbon::now()->timestamp, 'ip' => '83.46.154.71' ],
'individual' =>
[
'dob' => [ 'day' => $request->userDOBday, 'month' => $request->userDOBmonth, 'year' => $request->userDOByear ],
'first_name' => $request->userName,
'email' => $request->userEmail,
'phone' => $request->userPhone,
'last_name' => $request->userSurname,
//'ssn_last_4' => 7871,
'address' => [ 'city' => $request->userBusinessCity, 'line1' => $request->userBusinessAddress, 'postal_code' => $request->userBusinessZipCode, 'state' => $request->userBusinessCity ]
],
'business_profile' =>
[
'mcc' => 5812, //got it
'description' => '',
//'url' => 'https://www.youtube.com/?hl=es&gl=ES', //got it
],
'capabilities' => [
'card_payments' => ['requested' => true],
'transfers' => ['requested' => true],
],
]
);
return response()->json([
'account' => $account,
], 200);
Consider using a Form Request where you preform validation. This will neaten up your controller for a start and also make validation (never trust user input!) reusable.
Assuming validation is successful, calling $request->validated() from inside your controller method will return only the fields present and validated. You can then use either fill($request->validated()) or update($request->validated()).

required_if validation in laravel not give error if filed is input type file

I have one form where I have 5 text fields and 2 input type file fields.
for all 7 fields, I have written custom validation rules in laravel and I want all field required if a type is a business so I used required_if in all fields, for text field it's working but for an image (input type file) it's not working it always consider as file present in request and not give any error if file not uploaded when I changed it to required than it only gives me error for input type file.
public function rules()
{
return [
'country' => 'required_if:type,business',
'country2' => 'required_if:type,business',
'company' => 'required_if:type,business',
'number' => 'required_if:type,business',
'expiry' => 'required_if:type,business',
'profile_pic' => 'required_if:type,business | mimes:jpeg,jpg,png,pdf',
'document_pic' => 'required_if:type,business | mimes:jpeg,jpg,png,pdf',
];
}
You can try this:
public function rules()
{
return [
'country' => 'required_if:type,business',
'country2' => 'required_if:type,business',
'company' => 'required_if:type,business',
'number' => 'required_if:type,business',
'expiry' => 'required_if:type,business',
'profile_pic' => 'required_if:type,business|image',
'document_pic' => 'required_if:type,business|image',
];
}
Also can edit mine :https://laravel.com/docs/5.3/validation#rule-mimes
The issue is coming because of extra space invalidation rules.
Removed space between required if and mime type and its working properly.
public function rules()
{
return [
'country' => 'required_if:type,business',
'country2' => 'required_if:type,business',
'company' => 'required_if:type,business',
'number' => 'required_if:type,business',
'expiry' => 'required_if:type,business',
'profile_pic' => 'required_if:type,business|mimes:jpeg,jpg,png,pdf',
'document_pic' => 'required_if:type,business|mimes:jpeg,jpg,png,pdf',
];
}

How to give Free Bonus in laravel?

I am runing a bitcoin investment website. I want to give user free bonus of 0.005 points on registration. I have tried following in my registration Controller to fill database table. It works perfectly but after 100 user it creat some type of bug and I get error in user login it says:
But I remove all rows of depostit table all functions work perfectly.
trying to get property of non object
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'under_reference' => $data['reference'],
'password' => bcrypt($data['password']),
'verifyToken' => Str::random(40),
'reference' => Str::random(12),
'status' => $status,
'image' => $image25
]);
$deposit = Deposit::create([
'deposit_number' => date('ymd').Str::random(6).rand(11,99),
'user_id' => $user->id,
'plan_id' => "7",
'percent' => "1",
'time' => "30",
'compound_id' => "2",
'amount' => "0.005",
'status' => "0"
]);

How test required_if with more than one value

I am newbie with Laravel and picked up a system to give maintenance.
I have this rule:
protected $rules = array(
'per_vlr_principal_rte' => 'required_if:per_fase_processual,2',
'per_vlr_juros_rte' => 'required_if:per_fase_processual,2',
'per_vlr_principal_rdo' => 'required_if:per_fase_processual,1,2',
'per_vlr_juros_rdo' => 'required_if:per_fase_processual,1,2',
'per_vlr_principal_perito' => 'required_if:per_fase_processual,2',
'per_vlr_juros_perito' => 'required_if:per_fase_processual,2',
'per_vlr_homologado' => 'required_if:per_fase_processual,2',
'per_qte_rte' => 'required',
'per_competencias' => 'required',
'per_qte_laudo' => 'required',
'per_dt_calculo' => 'required'
);
I'd like to know if the code below is correct:
'per_vlr_principal_rdo' => 'required_if:per_fase_processual,1,2',
'per_vlr_juros_rdo' => 'required_if:per_fase_processual,1,2',
The validation occurs only when the value is 1.
How to fix it?

Categories