我正在制作一个漂亮的Web应用程序,并在尝试使用命令缓存视图时出错:
$view = View::make('templates.view1', array(
'a' => $a,
'b' => $b
));
Cache::put($key, $view, 30);
Run Code Online (Sandbox Code Playgroud)
它抛出
不允许序列化'闭包'
在我脸上 我尝试过记住方法但没有成功.
Cache::remember($key, 30, function($a, $b){
return View::make('templates.view1', array(
'a' => $a,
'b' => $b
));
});
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
我在我的项目中使用 Laravel,我创建了一个服务提供者,它位于 中app/services/ToolboxServiceProvider.php,我添加了
'providers' => array(
....
'services\ToolboxServiceProvider',
);
Run Code Online (Sandbox Code Playgroud)
在我的 app.php 配置文件中。现在在加载应用程序时,它说服务提供者找不到,我知道我在该提供者数组中的路径设置有问题,问题是:如何使它正确?提前致谢。
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.2.*"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "stable"
Run Code Online (Sandbox Code Playgroud)
}
任何人都可以帮助我理解为什么以下代码工作
$x = $widget->objGallery->galleryItems()->with(array('captions' => function($query){ $query->where('locale', 'IT' );}))->get() ;
Run Code Online (Sandbox Code Playgroud)
但是当我使用动态值时
$id='11';
$x = $widget->objGallery->galleryItems()->with(array('captions' => function($query){ $query->where('locale', $id );}))->get() ;
Run Code Online (Sandbox Code Playgroud)
在说
方法Illuminate\View\View :: __ toString()不得抛出异常
我试图在Windows 7上设置宅基laravel流浪汉,我得到这个错误:
C:/HashiCorp/Vagrant/embedded/lib/ruby/2.0.0/psych.rb:205:in `parse':
(<unknown>): mapping values are not allowed in this context at line 13
column 9 (Psych::SyntaxError)
Run Code Online (Sandbox Code Playgroud)
这是我的yaml文件:
authorize: C:/Users/Netanel/.ssh/id_rsa.pub
keys:
- C:/Users/Netanel/.ssh/id_rsa
folders:
- map:C:/projects
to: /home/vagrant/projects
sites:
- map: test.com
to: /home/vagrant/projects/test/public
variables:
- key: APP_ENV
value: local
Run Code Online (Sandbox Code Playgroud) 我只是想从Scratch构建PHP7.
我使用了这个命令:
cd php-7.0.0
./configure --prefix=/usr/local/php/7.0.0 --with-pdo-pgsql --with-zlib-dir --with-freetype-dir --enable-mbstring --with-libxml-dir=/usr --enable-soap --enable-calendar --with-curl --with-mcrypt --with-zlib --with-gd --with-pgsql --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-exif --enable-bcmath --with-mhash --enable-zip --with-pcre-regex --with-pdo-mysql --with-mysqli --with-mysql-sock=/var/run/mysqld/mysqld.sock --with-jpeg-dir=/usr --with-png-dir=/usr --enable-gd-native-ttf --with-openssl --with-fpm-user=www-data --with-fpm-group=www-data --with-libdir=/lib/x86_64-linux-gnu --enable-ftp --with-imap=shared,/usr --with-imap-ssl --with-kerberos --with-gettext --with-xmlrpc --with-xsl --enable-opcache --enable-fpm --sysconfdir=/etc/php7/ --with-xpm-dir=/usr --enable-intl --with-ldap --enable-mysqlnd --with-pear=/usr/local/php/7.0.0/pear --with-apxs2 --enable-dtrace --disable-phpdbg --enable-zend-signals
make clean
make
Run Code Online (Sandbox Code Playgroud)
但它打破了错误消息:
/bin/sh /usr/src/php7/php-7.0.0/libtool --silent --preserve-dup-deps --mode=compile cc -Iext/imap/ -I/usr/src/php7/php-7.0.0/ext/imap/ -DPHP_ATOM_INC -I/usr/src/php7/php-7.0.0/include -I/usr/src/php7/php-7.0.0/main -I/usr/src/php7/php-7.0.0 -I/usr/src/php7/php-7.0.0/ext/date/lib -I/usr/include/libxml2 -I/usr/X11 …Run Code Online (Sandbox Code Playgroud) 我在Laravel 5.1上有一个小项目
我将其更新为5.2
现在我从我的模型中得到了这个错误:
Class 'Input' not found
这是代码:
if ( \Input::get('angular') ) { ... }
我在哪里可以找到它?
我是Laravel的新手
而我没有找到它
谢谢您的帮助
我在Laravel 5.1上具有空值的模型上的关系存在问题。
我有2个表任务和用户。在“任务”中,我具有id_requester和id_responsible列。
我想显示所有任务,我总是有一个请求者,但有时我还没有一个负责人。
因此,在这种情况下,id_responsible为null。
我的模特是:
protected $table = 'tasks';
protected $fillable = array(
'id_requester',
'id_responsible',
);
public function requester()
{
return $this->hasOne('app\User', 'id', 'id_requester');
}
public function responsible()
{
return $this->hasOne('app\User', 'id', 'id_responsible');
}
Run Code Online (Sandbox Code Playgroud)
我的控制器中的查询是:
$tasks = Tasks::get();
Run Code Online (Sandbox Code Playgroud)
我试图在这样的视图中显示:
<table>
...
@foreach($tasks as $task)
<td>{{ $task->requester->name }}</td>
<td>{{ $task->responsible->name }}</td>
@endforeach
...
</table>
Run Code Online (Sandbox Code Playgroud)
问题是,当我尝试访问该页面时,出现错误“试图获取非对象的属性”。
我已经测试过了,这只有在我有一个id_responsible = Null的时候。
如何解决此问题以显示所有寄存器?
谢谢!!!
我只是将我的L5.2应用程序推送到生产服务器.我做了一些更改,但突然间我收到以下错误:
PHP Fatal error: Declaration of Illuminate\Auth\SessionGuard::basic($field = 'email')
must be compatible with
Illuminate\Contracts\Auth\SupportsBasicAuth::basic($field = 'email', $extraConditions
= Array) in /home/forge/domain.com/bootstrap/cache/compiled.php on line 461
Run Code Online (Sandbox Code Playgroud)
该应用程序在本地和登台服务器上工作正常.
我正在使用 Laravel 5.5 和 Dusk 2.0。我有以下 html。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body class="my-body-class" id="my-body-div">
<div class="my-content-class" id="my-content-div">
Content goes here.
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是我的黄昏测试。
public function testBasicExample()
{
$this->browse(function (Browser $browser) {
$browser->visit('/test/admin-fixed-layout');
$this->assertNotNull($browser->element('.my-content-class'));
$this->assertNotNull($browser->element('#my-content-div'));
// $this->assertNotNull($browser->element('.my-body-class'));
$this->assertNotNull($browser->element('#my-body-div'));
});
}
Run Code Online (Sandbox Code Playgroud)
如果我取消注释使用主体类选择器的断言,则测试失败。为什么?
我试图从我的产品表中获取独特品牌的数量,以及来自 Laravel 集合的数量。
我能够使用产品的特定查询来做到这一点,但我现在使用集合的原因是因为我还想获得产品的产品来源(国家/地区)、条件(使用/新),我认为它使用来自一个查询的集合会更好,而不是对每个数据使用三个单独的查询。
下面的代码有效,但没有显示每个唯一品牌的计数。
这是我的控制器
$products = DB::table('products')
->select('products.*')
->whereNull('products.deleted_at')
->get();
$BrandCollection = collect($products);
$Brands = $BrandCollection->unique('Brand')->sortBy('Brand')->keyBy('Brand')->pluck('Brand');
Run Code Online (Sandbox Code Playgroud)
所以,我正在寻找的结果是
惠普 3
东芝 2
联想 1
我认为可以使用 concat 来完成集合,但由于我使用的是 Laravel 5.2,我正在寻找其他解决方案。
laravel ×8
php ×6
laravel-5 ×4
laravel-4 ×3
laravel-5.2 ×3
blade ×2
composer-php ×2
laravel-5.1 ×2
closures ×1
compilation ×1
eloquent ×1
homestead ×1
laravel-5.5 ×1
laravel-dusk ×1
php-7 ×1
vagrant ×1
view ×1