how to allow letters and enye only [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Where do I put the enye in my regex validation? Do i just put it beside regex for letters?
I want to accept enyes in fname,lname, and mname.
return [
'fname' => 'required|max:255|regex:/^[a-zA-Z\s]+$/',
'lname' => 'required|max:255|regex:/^[a-zA-Z\s]+$/',
'mname' => 'max:255|alpha',
'file' => 'image|mimes:jpg,jpeg,png',
'contact_no' => 'regex:/^[-0-9\+]+$/',
'date_of_birth' => 'required|date_format:Y-m-d',
'school_id' => 'required|exists:schools,id',
'degree_id' => 'required|exists:degrees,id',
];

Thanks for the answer guys but I got it working. I just used
return [
'fname' => 'required|max:255|regex:/^[a-zA-ZÑñ\s]+$/',
'lname' => 'required|max:255|regex:/^[a-zA-ZÑñ\s]+$/',
'mname' => 'max:255|alpha',
'file' => 'image|mimes:jpg,jpeg,png',
'contact_no' => 'regex:/^[-0-9\+]+$/',
'date_of_birth' => 'required|date_format:Y-m-d',
'school_id' => 'required|exists:schools,id',
'degree_id' => 'required|exists:degrees,id',
];

The bytes it needs to match for enye depends on the character encoding of your string (hopefully it is utf8). So you'll need a multibyte encoding-aware regex function. Fortunately, PHP has 'em ...
$pattern = '/^[ñÑa-zA-Z\s]+$/';
mb_regex_encoding('UTF-8');
mb_ereg($pattern, $testString, $matches);
where $pattern has your regex with enye's typed in with UTF8 encoding.

Related

PHP Variable of Stripe API [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I need help with PHP and the Stripe API.
$stripe->accountLinks->create([
'account' => 'acct_1HtKYcRm0s9vfiNs',
'refresh_url' => 'https://example.com/reauth',
'return_url' => 'https://example.com/return',
'type' => 'account_onboarding',
]);
That gives me back an answer like this:
{
"object": "account_link",
"created": 1606772720,
"expires_at": 1606773020,
"url": "https://connect.stripe.com/setup/s/QaVzgu7GNGFP"
}
I need help to know how to display the "url" in a variable in PHP.
I've tried to do this but it doesn't work:
$link = $stripe->accountLinks->create([
'account' => 'acct_1HtKYcRm0s9vfiNs',
'refresh_url' => 'https://example.com/reauth',
'return_url' => 'https://example.com/return',
'type' => 'account_onboarding',
]);
$data = json_decode($link);
$links = $data->url;
If someone knows what I can do it would help me a lot. Thanks :)
EDIT:
The var_dump returns this:
object(Stripe\AccountLink)#127 (4) { ["object"]=> string(12) "account_link" ["created"]=> int(1606856512) ["expires_at"]=> int(1606856812) ["url"]=> string(47) "https://connect.stripe.com/setup/c/vD45DxCl0hZQ" }
But I just need url string
You do not need to json_decode the resulting account link object. All you need to do is access the URL property on the object returned by Stripe. For example:
$link = $stripe->accountLinks->create([
'account' => 'acct_1HtKYcRm0s9vfiNs',
'refresh_url' => 'https://example.com/reauth',
'return_url' => 'https://example.com/return',
'type' => 'account_onboarding',
]);
$url = $link->url;
echo $url;
You can use the $url variable in a template or to perform any other server-side logic. The structure of the returned account link object can be referenced here:
https://stripe.com/docs/api/account_links/object
I've made it work by doing this:
$link = $stripe->accountLinks->create(
[
'account' => 'acct_1HtKYcRm0s9vfiNs',
'refresh_url' => 'https://example.com/reauth',
'return_url' => 'https://example.com/return',
'type' => 'account_onboarding',
]
);
$var_url = var_export($link->url, true);
$good_url = str_replace("'", "", $var_url);
Now when I echo "good_url" I get the full url successfully.
Thank you all very much, really, you have helped me a lot.

PHP / Laravel Not Accepting .upd Files As A File [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I need to upload update files for Android device updates. I need to upload two file extentions, first is .apk and the second is .upd. I have no problem with .apk but when I'm trying upload .upd files, it doesn't event get passed from validation.
I also tried it with simple PHP script, it only seems name and errors:
I couldn't find anyting on uploading .udp files with PHP or Laravel. I'd appreciatethe help, thank you very much.
Here is validation method:
private function validateRequest($request)
{
$fields = [
'file_type' => 'required',
'update_file' => 'required|file',
'swid' => 'required',
'software' => 'required',
'box_name' => 'required',
'apk_version' => 'sometimes|required',
'dongle_firmware_version' => 'sometimes|required',
'change_log' => 'required',
];
return Validator::make($request->all(), $fields )
->setAttributeNames([
'file_type' => 'File type',
'swid' => 'Software ID',
'software' => 'Software',
'box_name' => 'Box name',
'apk_version' => 'Android version',
'dongle_firmware_version' => 'Dongle firmware version',
'change_log' => 'Change log',
'update_file' => 'Update file'
]);
}
Error codes are documented. Yours is UPLOAD_ERR_INI_SIZE:
Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.
If you need to upload larger files, just allow a larger size ;-)

How to store laravel log file data into database(5.5) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I need to store the Laravel log into my database . Can you please help me?
Go to App/Exceptions/Handler.php and then write below code in report() function and define your model as an ErrorLog
$data = [
'id' => $this->createUniversalUniqueIdentifier(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'message' => $exception->getMessage(),
'trace' => $exception->getTraceAsString(),
];
$dataArr =['id' => $data['id'],
'file' => $data['file'],
'error_summary' => 'Line '.$data['line'].' '.$data['message'],
'log_trace' => $data['trace']
];
ErrorLog::create($dataArr);
Your Model file should be like that
ErrorLog.php
protected $table = 'logs';
protected $fillable =
['id',
'file',
'error_summary',
'log_trace'
];
Laravel supports Monolog for handling logs. Monolog supports many different handlers, including database handlers like the MongoDB handler.
You can use the MongoDB handler by adding a new channel to the channels array in your config/logging.php file, e.g.:
'channels' => [
'mongolog' => [
'driver' => 'monolog',
'handler' => Monolog\Handler\MongoDBHandler::class,
'with' => [
'database' => 'mongo-database-name',
'collection' => 'log-collection-name',
],
],
Then you can set your default log channel to mongolog in your .env file, e.g. LOG_CHANNEL=mongolog.

Laravel 5.1 Validation not ignoring unique on update [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Hi I'm having trouble getting laravel to ignore an unique identifier rule when updating. I've tried using $member->id, $id ,'.$member->id ,'.$id etc
public function rules()
{
return [
'first' => 'required|min:2',
'last' => 'required|min:2',
'mobile' => ['required','regex:^(\+614)+([0-9 {8})$^','unique:members,mobile,$id'],
];
}
To use the $id variable in the string, double quote it:
['required','regex:^(\+614)+([0-9 {8})$^',"unique:members,mobile,$id"]
// ^ ^
As long as you are inside a Form Request Validation, you should be able to do this:
['required','regex:^(\+614)+([0-9 {8})$^','unique:members,mobile,'.$this->get(id)]
If you are using Requests for form validation , you can do like this for unique validation :
'unique:table_name ,
unique_column,'.$this->route->getParameter('parameter').',primary_key'
public function rules()
{
return [
'first' => 'required|min:2',
'last' => 'required|min:2',
'mobile' => 'required | regex:^(\+614)+([0-9 {8})$^| unique:members,mobile,'.$this->route()->getParameter('id').',id',
];
}

Getting values depend on url [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have this array again:
$predmeti = [
'slo' => [
'ime' => 'Slovenščina',
'ucitelj' => 'Ana Berčon',
'nadimek' => '',
'ucilnica' => '11'
],
'mat' => [
'ime' => 'Matematika',
'ucitelj' => 'Nevenka Kunšič',
'nadimek' => '',
'ucilnica' => '12'
],
'ang' => [
'ime' => 'Angleščina',
'ucitelj' => 'Alenka Rozman',
'nadimek' => 'Rozi',
'ucilnica' => '3'
],
'mob' => [
'ime' => 'Medijsko oblikovanje',
'ucitelj' => 'Iztok Mulej',
'nadimek' => 'HTML ninja',
'ucilnica' => 'MM2'
]
];
I want to get values of every key depend on url I am accesing. For example I have url /predmet?ime=slo, then I want to get data only for key 'slo'.
How do I achieve that?
if(isset($_GET['ime']) && isset($predmeti[$_GET['ime']])){
$data = $predmeti[$_GET['ime']];
}
Use the parameter in the URL
<?php
$param = $_GET['ime'];
print_r($predmeti[$param]);
?>

Categories