可能重复:
如何使用JavaScript查找操作系统版本
我如何能够检测到我的访问者在javascrtip中使用哪个os和os版本.例如windows vista或者七或者Xp和linux.
我有一个这样的脚本:
<html>
<body>
<?php
require("wrongFile.php");
echo "Hello World!";
?>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
现在如果错误文件不存在,则会报告以下两个错误:
警告:require(wrongFile.php)[function.require]:无法打开流:第5行的C:\ home\website\test.php中没有这样的文件或目录
致命错误:require()[function.require]:在第5行的C:\ home\website\test.php中打开所需的'wrongFile.php'(include_path ='.; C:\ php5\pear')失败
我知道如果不存在require()函数中的文件,则显示致命错误导致脚本执行停止但不明白什么是第一个错误
使用include()函数时的第一个错误显示
我希望通过Feed获取新闻或网站帖子的完整内容.但是我们知道许多网站只提供部分新闻或通过他们的Feed发布.
当然我知道存在一个称为SimplePie开发用于通过feed获取网站内容的脚本.但是此脚本不会检索新闻的完整内容.
当然我发现了一个叫做" Full-Text Feeds做" 的脚本.但这不是免费的.我想要一个免费的剧本.
你知道类似的剧本或方式来满足我的需求吗?
出于技术原因并在我的PHP网站上测试新功能,我想暂时禁止普通用户访问该网站,并显示诸如“站点正在维护”之类的消息。
但是,我希望能够访问所有页面,并且可以正常使用。
如何使用htaccess,php代码或其他方法来做到这一点?
我使用Zizaco/ entrust laravel 包作为我项目的 ACL 管理器。
我知道为了通过中间件限制对路由组的访问并为其分配角色(或权限),我应该这样做:
Route::group(['prefix' => 'admin', 'middleware' => ['role:admin']], function() {
....
});
Run Code Online (Sandbox Code Playgroud)
但我想为资源控制器的不同路由(方法)分配单独的权限。
我知道如何才能为整个资源做到这一点,但我无法为每个控制器方法实现它:
Route::group(['prefix' => 'admin', 'middleware' => ['role:admin']], function() {
Route::resource('/post', ['middleware' => ['permission:manage-posts'], 'uses' => 'PostController']);
});
Run Code Online (Sandbox Code Playgroud)
我想将此权限分配给相关方法:
'post-create' => public function create ()
'post-edit' => public function edit()
Run Code Online (Sandbox Code Playgroud)
等等。
问题是显而易见的。
我们知道 withRoute::getRoutes()方法可以获取 laravel 项目中所有定义的路由,如下所示:
$routeCollection = Route::getRoutes();
$arr = [];
foreach ($routeCollection as $value) {
$arr[] = $value->getPath();
}
return array_unique($arr);
Run Code Online (Sandbox Code Playgroud)
但我想获取特定路径中的所有定义的路由,例如/admin。
我认为可以传递路径名来getRoutes()执行此操作,但对我不起作用。
我怎样才能做到这一点 ?
我有这样的Post模型:
class Post extends Model
{
protected $primaryKey = 'post_id';
public function tags ()
{
return $this->belongsToMany('App\Tag');
}
}
Run Code Online (Sandbox Code Playgroud)
和Tag模型:
class Tag extends Model
{
public function posts ()
{
return $this->belongsToMany('App\Post');
}
public function tagsCount ()
{
return $this->belongsToMany('App\Post')
->selectRaw('count(pt_id) as count')
->groupBy('tag_id');
}
public function getTagsCountAttribute()
{
if ( ! array_key_exists('tagsCount', $this->relations)) $this->load('tagsCount');
$related = $this->getRelation('tagsCount')->first();
return ($related) ? $related->count : 0;
}
}
Run Code Online (Sandbox Code Playgroud)
(pt_id列是post_tag数据透视表中的主键字段).
如您所见,和Models 之间存在ManyToMany关系.Post …
我有一个Message这样的模型:
class Message extends Model
{
protected $primaryKey = 'message_id';
protected $dates = ['created_at', 'updated_at', 'receiver_deleted_at', 'sender_deleted_at', 'sender_read_at', 'receiver_read_at'];
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,有一些日期字段将日期保存为DATETIME(YYYY-MM-DD HH:MM:SS)格式。
但我希望当获取模型实例时,所有日期字段都转换为unix-timestamp格式,然后返回。
我知道可以对每个字段使用这样的访问器:
public function getCreatedAtAttribute()
{
dd(strtotime($this->attributes['created_at']));
return strtotime($this->attributes['created_at']);
}
Run Code Online (Sandbox Code Playgroud)
但在这种情况下,我必须为每个字段定义一个像上面这样的函数。
但我想要一种更简单的方法来强制模型以 unix-timestamp 格式返回日期字段。
我有一个Cart这样的模型:
class Cart extends Model
{
protected $table = 'cart';
protected $fillable = ['user_id', 'delivery_method'];
public function products ()
{
return $this->belongsToMany(Product::class, 'cart_products', 'cart_id', 'product_id')->withPivot('quantity');
}
}
Run Code Online (Sandbox Code Playgroud)
和购物车表列是:
id
user_id
delivery_method
created_at
updated_at
Run Code Online (Sandbox Code Playgroud)
并且有一个数据透视表,命名cart_products为将Card模型与模型相关联Product。
假设我有一个特定的$user_id变量。现在,我想要带有该user_id的购物车及其产品。为此我写了这个:
$cartWithProducts = Cart::with('products')->where(['user_id' => $user_id])->first();
if (!$cartWithProducts->isEmpty()) {
//Some codes come here
}
Run Code Online (Sandbox Code Playgroud)
但是运行后,我得到了这个错误:
Call to undefined method Illuminate\Database\Query\Builder::isEmpty() {"exception":"[object] (BadMethodCallException(code: 0): Call to undefined method Illuminate\\Database\\Query\\Builder::isEmpty() at D:\\wamp\\www\\barlly\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Query\\Builder.php:2461
Run Code Online (Sandbox Code Playgroud)
由于查询问题,我不想使用延迟加载 …
我正在使用PHP-FFMpeg库来处理音频和视频文件.
我知道要获得特定视频的持续时间可以这样:
$ffprobe = \FFMpeg\FFProbe::create();
$duration = $ffprobe->format('path/to/file')->get('duration');
Run Code Online (Sandbox Code Playgroud)
但我知道如何为给定的音频文件执行此操作.
有人知道解决方案吗?
php ×9
laravel ×6
.htaccess ×1
entrust ×1
feed ×1
ffmpeg ×1
javascript ×1
laravel-5.3 ×1
laravel-5.5 ×1
mysql ×1
simplepie ×1