Home  >  Article  >  Backend Development  >  Lumen 常用开发技巧

Lumen 常用开发技巧

WBOY
WBOYOriginal
2016-06-23 13:10:581000browse

加密

<?php/*** 密码入库加密* @param string $password* @return string** */public function passwordEncrypt($password){    return app('hash')->make($password);}

密码验证

<?php/*** 密码验证* @param string $password* @param string $hashedPassword 加密后的密码* @return bool** */public function passwordValidate($password, $hashedPassword){    return app('hash')->check($password, $hashedPassword);}

查询数据库判断是否有记录

如果使用 Eloquent 的 Query Scopes,查询时使用链式方法调用,通常是这么查询, $modelObj = Model::id($id)->get()来查询指定条件的结果集。但是这么查出来的,实际上返回的是 Illuminate\Support\Collection对象。那么下面的方法,比较适合判断查出来的结果是否存在。

<?php$modelObj = Model::id($id)->get();if (! $modelObj->isEmpty()) {    $modelObj->toArray();}// 或者这样if ($modelObj->count()) {    $modelObj->toArray();}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn