doc中的示例:
DB::table('users')
->whereExists(function($query)
{
$query->select(DB::raw(1))
->from('orders')
->whereRaw('orders.user_id = users.id');
})
->get();
Run Code Online (Sandbox Code Playgroud)
但是如果我需要像这样使用外部变量呢:
->where('city_id', '=', $this->city->id)
->where(function($query)
{
$query->where('name', 'LIKE', '%'.$searchQuery.'%')
->orWhere('address', 'LIKE', '%'.$searchQuery.'%')
})
Run Code Online (Sandbox Code Playgroud)
现在我创建了新属性并通过它访问了$this->,但还有更方便的方法吗?
我是Laravel的新手.根据我对这个框架的研究,我发现它对我的项目非常有用.但是我在定制它时遇到了困难,因为Laravel框架的单个实例用于多个项目.我不想遵循Laravel中提供的多站点方法,即在项目的模型和控制器中使用目录结构,因为我无法在Git中的一个步骤中推送与项目相关的更改.
我想要这样的东西.
常见的Laravel框架(具有通用库和供应商文件.还具有不同项目使用的通用功能)
应用程序/控制器
应用程序/模型
应用程序/意见
供应商
引导
Proj1(拥有自己的实体,能够使用常见Laravel框架中的公共库和模型函数)
应用程序/控制器
应用程序/模型
应用程序/意见
引导
Proj2(拥有自己的实体,能够使用常见Laravel框架中的公共库和模型函数)
应用程序/控制器
应用程序/模型
应用程序/意见
引导
即,新项目必须有自己的应用程序目录,并且能够使用来自普通项目的模型函数.
这将简化我的任务,对我即将开展的项目非常有用.如果有人可以帮助我,我会非常感激.
我在InnoDB中有关于删除操作的表锁定问题.我有一个表队列,例如一列和许多事务,可以将行插入此队列或删除它们.没有任何两个事务同时使用相同的行.因此,所有行锁必须是不同的.但有时当删除操作删除表中的大部分行时,InnoDB更喜欢使用表锁而不是行锁,这会导致死锁.
我无法准确地重现这个死锁,但我发现了锁定问题.即我有表队列:id值(1,3,4,5,6,7)
交易1:
insert into queue value(2);
Run Code Online (Sandbox Code Playgroud)
交易2:
delete from queue where id in (1,3,4,5,6,7); -- here the lock comes
Run Code Online (Sandbox Code Playgroud) 好的,这个问题源于Laravel 4.1.23安装.我正在尝试使用Eloquent update()方法在包含连接的查询上更新多个记录:
ChildSchoolYear::whereNull('exit_date')->
join('school_years', 'child_school_years.school_year_id','=','school_years.id')->
update(array('child_school_years.exit_date'=>'`school_years`.`end_date`',
'child_school_years.editor_id'=>$userId))
Run Code Online (Sandbox Code Playgroud)
Laravel正在为我上面提供的查询内容生成正确的SQL,但生成的完整SQL语句是
update `child_school_years`
inner join `school_years` on `child_school_years`.`school_year_id` = `school_years`.`id`
set `child_school_years`.`exit_date` = `school_years`.`end_date`,
`child_school_years`.`editor_id` = 2,
`updated_at` = 2014-08-15 02:00:33 where `exit_date` is null)
Run Code Online (Sandbox Code Playgroud)
这将起作用,除了updated_atchild_school_years和school_years表中都存在自动添加的字段,因此Laravel 添加字段会触发异常Integrity constraint violation: 1052 Column 'updated_at' in field list is ambiguous.
关于如何驯化updated_at作品的任何建议?我很乐意让这个领域更新,但是如果有必要的话,如果有必要可以消除它,我会活下去.
我今天遇到了一个问题,我似乎无法找到解决方案.
我正在为图片上传创建一个类.上传本身工作正常,但是当我尝试使用上传的文件创建缩略图时,由于某种原因无法找到该文件.
我的代码:
private static $imageTypes = [
"image/jpeg", "image/png", "image/gif", "image/x-ms-bmp"
];
public function upload(UploadedFile $file, $folder = 'common')
{
if (!$this->isImage($file)) {
return false;
}
$path = $this->createPath($file, $folder);
try {
$file->move($path, $file->getClientOriginalName());
$filePath = sprintf("%s/%s", $path, $file->getClientOriginalName());
} catch (FileException $e) {
return false;
}
$realPath = 'public/' . $filePath;
//dd(File::exists($realPath)); - this returns false
//dd(File::get($realPath)); - this throws the exception
$image = Image::make(File::get($realPath));
// Code for creating a thumbnail - not implemented yet.
$thumbnailPath = ''; …Run Code Online (Sandbox Code Playgroud) 如何收听特定控制器的调度事件?目前我做了以下事情:
Module.php
public function onBootstrap(EventInterface $event) {
$application = $event->getApplication();
$eventManager = $application->getEventManager();
$serviceManager = $application->getServiceManager();
$eventManager->attach($serviceManager->get('MyListener'));
}
Run Code Online (Sandbox Code Playgroud)
MyListener.php
class MyListener extends AbstractListenerAggregate {
public function attach(EventManagerInterface $eventManager) {
$this->listeners[] = $eventManager->attach(
MvcEvent::EVENT_DISPATCH, function($event) {
$this->setLayout($event);
}, 100
);
}
public function setLayout(EventInterface $event) {
$event->getViewModel()->setTemplate('mylayout');
}
}
Run Code Online (Sandbox Code Playgroud)
这将设置所有控制器调度的布局.现在我只想在应用程序调度特定控制器时设置布局.
我有一个登录表单
username,password和remember me
remember me 是一个复选框(true或false).
如何在Laravel中创建验证规则? http://laravel.com/docs/validation#basic-usage
它看起来唯一相关的是in你指定的值,但在这种情况下的值是布尔值,并使用这种方法,他们将被指定为字符串?
in:true,false
所以我正在做的是,当我选中“记住我”复选框时,用户在注销表单(用户名和密码)时会记住这样的用户数据:
所以这是我的代码它不起作用:(
// create our user data for the authentication
$userdata = array(
'email' => Input::get('email'),
'password' => Input::get('password')
);
// attempt to do the login
if (Auth::attempt($userdata, true)) {
Session::flash('message', array('body'=>trans('login-signup.welcome'), 'type'=>'success'));
return Redirect::to('/');
}
Run Code Online (Sandbox Code Playgroud) 我创建了一个 Laravel 包,将它上传到 packagist 并设法使用 composer require 安装它。
我现在遇到了一个问题,我不知道如何解决它,搜索也无济于事。
我有一个配置文件,它将默认配置文件发布到 config 目录。我对已发布的文件进行了更改,现在我希望我的包使用此配置文件,但它使用的是包中的配置文件,而不是新更新的发布文件。这是我在 vendor src 文件夹中的服务提供者
namespace Clystnet\Vtiger;
use Illuminate\Support\ServiceProvider;
class VtigerServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
$this->publishes([
__DIR__ . '/Config/config.php' => config_path('vtiger.php'),
], 'vtiger');
// use the vendor configuration file as fallback
$this->mergeConfigFrom(
__DIR__ . '/Config/config.php', 'vtiger'
);
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
$this->app->bind('clystnet-vtiger', function () …Run Code Online (Sandbox Code Playgroud) 我一直在关注Crystal的官方文档,但我找不到任何关于此的细节.声明联合类型时的常规语法是String | Int32.但是,我注意到了Nil类型的不同.
宣布联盟的常规方式仍然有效:
def foo(id : String | Nil)
end
# Overloads are:
# - foo(id : String | Nil)
Run Code Online (Sandbox Code Playgroud)
但是我也看到了一个缩短的语法,我找不到任何文档:
def foo(id : String?)
end
# Overloads are:
# - foo(id : String | ::Nil)
Run Code Online (Sandbox Code Playgroud)
结果几乎完全相同,除非Nil前缀为2个冒号.我猜这是与Nil我在其他语言中看到类似语法的全局范围有关的东西.
String | Nil和String?同样的事情,什么时候应该使用一个与另一个?::Nil)?php ×7
laravel ×6
laravel-4 ×5
config ×1
crystal-lang ×1
deadlock ×1
eloquent ×1
innodb ×1
instance ×1
mysql ×1
packages ×1
projects ×1
sql ×1
union-types ×1
validation ×1