What we have to pass, to the send argument of the following function?
Password::reset(array('email' => $input['email'], 'password' => $input['password'], 'password_confirmation' => $input['password_confirmation'], 'token' => $token), 'what we have to pass here');
you have to pass callback or Closure like below
function($user, $password)
{
//perform reset stuff
}
the closure will only fires when the reset request is valid.
Related
This is my controller method to process the user input
function do_something_cool()
{
if ($this->form_validation->run() === TRUE)
{
// validation passed process the input and do_somthing_cool
}
// show the view file
$this->load->view('view_file');
Validation Rules are as follow:
<?php
$config = array(
'controller/do_something_cool' => array(
array(
'field' => 'email',
'label' => 'Email',
'rules' => 'trim|required|valid_email|callback_check_email_exists',
)
)
);
My problem:
If the user input is not a valid email, the validation rule is not stopping from executing the next rule, that is callback function in this case. Therefore, even if the email is not valid, I am getting the error message for check_email_exists() callback.
Is there any option in CI to stop checking the other rules if a rule failed?
From system/libraries/Form_validation.php's _prepare_rules() method,
"Callbacks" are given the highest priority (always called), followed
by 'required' (called if callbacks didn't fail), and then every next
rule depends on the previous one passing.
That means, the input will be validated against the callbacks first. So we will have to check the input within the callback function itself.
For the above case, I have modified my callback function as follows
function check_email_exists($email)
{
if ($this->form_validation->valid_email($email) === FALSE)
{
$this->form_validation->set_message('check_email_exists', 'Enter a valid email');
return FALSE;
}
// check if email_exists in the database
// if FALSE, set validation message and return FALSE
// else return TRUE
}
I'm using Laravel Illuminate/Database outside of laravel application. I'm trying to pass the Eloquent model as my closure argument but its throwing an error. May be I'm passing it wrongly. My code is as following:
// Create a dummy subject (This is working absolutely fine)
SubjectModel::create(array(
'title' => 'Mathematics',
'description' => 'Math Subject',
'slug' => 'math',
'ka_url' => 'http://khanacademy.org/math'
));
$scrapper = new SubjectScrapper();
$scrapper->setUrl('');
This is not working. SubjectModel is not being passed in the following closure
$scrapper->runScrapper(function($subjects) use ($scrapper, SubjectModel $subjectModel) {
if(!empty($subjects))
{
foreach ($subjects as $subject) {
$urlParts = explode('/', $subject['url']);
$slug = end($urlParts);
$subjectModel::create(array(
'title' => $subject['subject_name'],
'slug' => $slug,
'ka_url' => $scrapper->getBaseUrl().$subject['link'],
));
}
}
});
Could anybody please tell me how to accomplish this task.
Try this. No need to pass object in closure
$scrapper = new SubjectScrapper();
$scrapper->setUrl('');
$scrapper->runScrapper(function($subjects) use ($scrapper, $output) {
SubjectModel::create(array(
'title' => 'Math',
'slug' => 'math',
'ka_url' => 'http://math'
));
$output->writeln('<info>Total Subjects Scrapped:: '.count($subjects).'</info>'.PHP_EOL);
});
I am using this packet:
https://github.com/barryvdh/laravel-omnipay
In my controller I added:
$params = [
'amount' => '10',
'issuer' => 22,
'description' => 'desc',
'returnUrl' => URL::action('PurchaseController#returnApi', [43]),
];
$response = Omnipay::purchase($params)->send();
if ($response->isSuccessful()) {
// payment was successful: update database
print_r($response);
} elseif ($response->isRedirect()) {
// redirect to offsite payment gateway
return $response->getRedirectResponse();
} else {
// payment failed: display message to customer
echo $response->getMessage();
}
Here is my omnipay.php conf file:
<?php
return array(
/** The default gateway name */
'gateway' => 'PayPal_Express',
/** The default settings, applied to all gateways */
'defaults' => array(
'testMode' => true,
),
/** Gateway specific parameters */
'gateways' => array(
'PayPal_Express' => array(
'username' => '',
'landingPage' => array('billing', 'login'),
),
),
);
But get this error:
call_user_func_array() expects parameter 1 to be a valid callback,
class 'Omnipay\Common\GatewayFactory' does not have a method
'purchase'
Anyone can help me set this?
I created app on paypal and have details about it but don't know how to set it with this API...
I recommend that you switch from PayPal Express to PayPal REST. It is newer and has better documentation.
I have looked through the laravel-omnipay package and I can't see a use case for it. I would just code to the omnipay package directly.
I recommend that you create a unique transaction ID for each transaction and provide that as part of the URLs for returnUrl and cancelUrl so that you can identify which transaction you are dealing with in the return and cancel handlers.
I think that you are taking the examples in the laravel-omnipay package too literally. You don't need or want those echo statements there. You should be capturing the response from purchase() even if it is a redirectResponse and doing a getTransactionReference() check on it, because you will need that transaction reference later, e.g. for transaction lookup. You should store it in the transaction record that you created before calling purchase().
You may use
use Omnipay\Omnipay;
in your controller, change it to
use Omnipay;
With my laravel project I'm trying to send an email with the following code:
$mailTo = "theemail#hotmail.com";
$mailToName = "hisname";
Mail::send('emails.message.showmessage', array( 'name' => $mailToName), function($message)
{
$message->to($mailTo, $mailToName)->subject('New message');
});
But I get the error:
Undefined variable: mailTo
How is this possible? I clearly set the variable with Undefined variable: mailTo, is it being unset in the Mail function?
To use a local variable inside a closure (aka anonymous function) you need to use use()
Mail::send('emails.message.showmessage', array( 'name' => $mailToName), function($message) use ($mailTo, $mailToName)
{
$message->to($mailTo, $mailToName)->subject('New message');
});
All variables specified in use will be available inside the closure all other won't.
How I can redirect from one action on controller to another action
on different controller with parameter?
I got number controller->number action to where I want go with one parameter,
from index controller->index action.
$redirector = $this->_helper->getHelper('Redirector');
$redirector->gotoSimple(
'action', // action to redirect to
'controller', // controller to redirect to
'default', // module
array('param1' => 'test', 'param2' => 'test2') // params
);
Try this :
$params = array('user' => $user, 'mail' => $mail);
$this->_helper->redirector($action, $controller, $module, $params);