如何修复未定义的变量错误?

时间:2018-02-12 04:41:36

标签: php

我在# /models/company.rb class Company < ApplicationRecord has_many :projects, dependent: :delete_all ... end # /models/project.rb class Project < ApplicationRecord has_many :tasks, dependent: :delete_all ... end # /models/task.rb class Task < ApplicationRecord has_many :task_times, dependent: :delete_all ... end # /models/task_time.rb class TaskTime < ApplicationRecord ... end 中定义了变量input,但这会产生未定义变量错误。

我的控制器代码如下:

$validator = $this->validator($input);

1 个答案:

答案 0 :(得分:0)

您可以使用isset函数来检查是否定义了变量

  if(isset($input)) {

   if($validator->passes()){
    $data = $this->create($input)->toArray();
    $data['token'] = str_randon[25];
    $user = User::find($data['id']);
    $user->token = $data['token'];
   `enter code here`
    $user->save();
    Mail::send('mails.confirmation', $data, function($message) use($data){
         $message->to($data['email']);
         $message->subject('regisrtation sucess and sendt mail');
    });
    return redirect(route['login'])->with('status', 'confirmation mail');
 }
}
 `enter code here`
return redirect(route('login'))->with('status', $validator->error);
`enter code here`

}