I´m using laravel. My UserController call a public function (validateToken) which is placed on the top of the controller. I call my function from an another public function, but this doesn´t return anything. this is my code:
use App\Comment;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Validator;
class UserController extends Controller
{
public function validateToken($token)
{
$user = User::where('token', $token)->first();
if(!isset($user))
{
return array(
'message' => "These credentials do not match our records.",
'success' => false
};
}
}
public function register(Request $request)
{
$input = Input::all();
$this->validateToken($input['token']);
return array(
'message' => 'Your account has been created successfully and is ready to use',
'token' => $input['token'],
'success' => true
);
}
It works if the validateToken code is placing inside the register function
if(!isset($user))condition fails. So write someelseto yourif.