有没有办法在 Windows 批处理/PowerShell 中找出文件的 MIME-TYPE(或者它被称为“Content-Type”...)?
我在我的项目中使用laravel 5.2我刚刚实现了一个本地范围(为简单起见,请使用laravel docs示例-https://laravel.com/docs/master/eloquent#local-scopes )
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
/**
* Scope a query to only include popular users.
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePopular($query)
{
return $query->where('votes', '>', 100);
}
}
Run Code Online (Sandbox Code Playgroud)
我打电话:
$users = App\User::popular()->get();
Run Code Online (Sandbox Code Playgroud)
它就像一个魅力
可以否定范围吗?
$users = App\User::Notpopular()->get();
Run Code Online (Sandbox Code Playgroud)
还是我必须手动实现上述范围的否定?如果是这样,有更好的方法吗?
先感谢您!
我正在创建一个大型的PHP项目,我对如何继续进行一个微不足道的疑问.
假设我们有一个类books,在这个类我有方法ReturnInfo:
function ReturnInfo($id) {
if( is_numeric($id) ) {
$query = "SELECT * FROM books WHERE id='" . $id . "' LIMIT 1;";
if( $row = $this->DBDrive->ExecuteQuery($query, $FetchResults=TRUE) ) {
return $row;
} else {
return FALSE;
}
} else {
throw new Exception('Books - ReturnInfo - id not valid.');
}
}
Run Code Online (Sandbox Code Playgroud)
然后我有另一种方法 PrintInfo
function PrintInfo($id) {
print_r( $this->ReturnInfo($id) );
}
Run Code Online (Sandbox Code Playgroud)
显然,代码示例仅是示例,而不是实际的生产代码.
在第二种方法中,我应该(再次)检查id是否为数字?或者我可以跳过它,因为在第一种方法中已经注意了,如果它不是异常将被抛出?
直到现在我总是用冗余支票编写代码(无论是否已在其他地方检查过,我也会在这里查看)
有最好的做法吗?只是常识吗?
提前感谢您的回复.
我正在Laravel Spark 1.0(Laravel 5.2)中编写应用程序.我为代理(api)身份验证编写了一个自定义中间件.这是代码:
<?php
namespace App\Http\Middleware;
use App\Agent;
use Closure;
use Illuminate\Http\Request;
class AgentAuth
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if( isset($request->token) && !empty($request->token) )
{
$agent = Agent::where('token', '=', $request->token)->first();
if( $agent != NULL )
{
$team = $agent->Team()->first();
$user = $team->User()->first();
$request->merge(['team' => $team ]);
$request->merge(['user' => $user ]);
return $next($request);
}
else {
return response('Unauthorized 2.', …Run Code Online (Sandbox Code Playgroud) php ×3
laravel ×2
batch-file ×1
coding-style ×1
content-type ×1
eloquent ×1
laravel-5 ×1
logic ×1
middleware ×1
request ×1
windows ×1