目前,我有一个到子域的路由组和另一个到主站点的路由组,如下所示:
Route::group(array('domain' => '{subdomain}.mysite.dev'), function() {
// Subdomain routes
Route::get('/', array('as' => 'home', 'uses' => 'SubdomainController@showHome'));
});
// Main
Route::get('/', array('as' => 'home', 'uses' => 'PublicController@showHome'));
Run Code Online (Sandbox Code Playgroud)
到目前为止,“mysite.dev”和“stuff.mysite.dev”或任何其他子域都运行良好。问题是它假设“www”(如“www.mysite.dev”)作为子域,我需要将其解释为主站点。
我正在尝试从 sql 表 A 中检索数据,修改一些列,然后将修改后的列插入到 sql 表 B 中。
然而我的问题是当我使用时:
$customer= new Customer;
$fakecustomer= new Fakecustomer;
$fake_customer_name_records = $fakecustomer->get()->toArray();
foreach($fake_customer_name_records as $record){
//process columns for each record
$fake_customer_name_records_arry[]=array(
'last_name'=>$last_name,
'first_name'=>$first_name,
'home_phone'=>$phonenumber,
);
}
$customer->insert($fake_customer_name_records_arry);
Run Code Online (Sandbox Code Playgroud)
它只能插入大约 1000 条记录。Laravel 有没有办法让我处理大约 60,000 条记录?
谢谢
我正在LARAVEL 4与MySQL后端一起使用。我是新手。
我有一个语句从 3 个不同的表返回记录,如下所示:
$templates = Template::with('children')
->leftJoin('template_masters', function($join) {
$join->on('templates.template_master_id', '=', 'template_masters.id');
})
->leftJoin('surveyes', function($join) {
$join->on('templates.survey_id', '=', 'surveyes.id');
})
->get([
'templates.id',
'templates.survey_id',
'surveyes.title', // Here I want the IFNULL() condition e.g. IFNULL('surveyes.title','templates.title')
'templates.type',
'templates.created_at',
'template_masters.is_default'
]);
Run Code Online (Sandbox Code Playgroud)
基本上这会创建一个类似的查询:
select `templates`.`id`,
`templates`.`survey_id`,
`surveyes`.`title`,
`templates`.`type`,
`templates`.`created_at`,
`template_masters`.`is_default`
from `templates`
left join `surveyes` on `templates`.`survey_id` = `surveyes`.`id`
left join `template_masters` on `templates`.`template_master_id` = `template_masters`.`id`
Run Code Online (Sandbox Code Playgroud)
但我想要这样的查询:
select `templates`.`id`,
`templates`.`survey_id`,
IFNULL(`surveyes`.`title`, `templates`.`title`),
`templates`.`type`,
`templates`.`created_at`,
`template_masters`.`is_default`
from `templates`
left join …Run Code Online (Sandbox Code Playgroud) 我们通常Redirect::back()在控制器内部使用重定向到上次访问的页面,但是,是否有 Laravel 函数可以在视图中用作链接?
我的目标是检查用户表中的所有用户,看看他们是否在线使用Laravel 4. 我也对谁没有登录感兴趣。稍后,我想打印 2 个单独的列表,列出谁在线、谁不在线?
Auth::check()Laravel 附带的功能吗?database?样本

机场表:
Schema::create('airports', function(Blueprint $table)
{
$table->increments('id');
$table->string('code');
$table->string('name');
$table->string('city');
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
航班表:
Schema::create('flights', function(Blueprint $table)
{
$table->increments('id');
$table->integer('number');
$table->integer('origin')->unsigned();
$table->foreign('origin')->references('id')->on('airports');
$table->integer('destination')->unsigned();
$table->foreign('destination')->references('id')->on('airports');
$table->integer('price');
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
飞行模型:
<?php
class Flight extends \Eloquent {
protected $fillable = ['number', 'origin', 'destination'];
public function origin(){
return $this->belongsTo('Airport');
}
public function destination(){
return $this->belongsTo('Airport');
}
}
Run Code Online (Sandbox Code Playgroud)
飞行控制器@索引:
public function index()
{
$flights = Flight::with('origin')->with('destination')->get();
return Response::json($flights, 200);
}
Run Code Online (Sandbox Code Playgroud)
部分回复:
[
{
"id": "1",
"number": "112",
"origin": null,
"destination": null,
"price": "232",
"created_at": "2014-12-28 11:49:44",
"updated_at": …Run Code Online (Sandbox Code Playgroud) 所以我的模型有两个简单的关系。然后急切加载完美地像这样工作:
Entry::with('author', 'lastModifiedBy')->...;
Run Code Online (Sandbox Code Playgroud)
但是说我想添加一个需要约束的新关系。例如:
public function foo() {
return $this->hasOne('Foo')->latest('id');
}
Run Code Online (Sandbox Code Playgroud)
然后为了急切加载这种关系,Laravel 建议这样做:
Entry::with(array('foo' => function($query) use ($id) {
$query->where('user_id', $id);
}))->...;
Run Code Online (Sandbox Code Playgroud)
但是如果我想包括我author和我的lastModifiedBy关系,我最终不得不这样做:
Entry::with(array(
'foo' => function($query) use ($id) {
$query->where('user_id', $id);
},
'author' => function() { },
'lastModifiedBy' => function() { }
))->...;
Run Code Online (Sandbox Code Playgroud)
我必须给这两个关系一个空函数。没有这些空函数的丑陋,有没有更简单的方法来做到这一点?
我想让我的日期字段记住我的旧输入
我有什么办法可以做到这一点吗?
这是我的代码
<div class="form-group">
<label for="date1">Date From: </label>
<input id="date1" name="date1" type="date" value="<?php echo date('Y-m-d'); ?>" class="form-control">
</div>
<div class="form-group">
<label for="date2">Date To: </label>
<input id="date2" name="date2" type="date" value="<?php echo date('Y-m-d'); ?>" class="form-control">
</div>
Run Code Online (Sandbox Code Playgroud)
请帮忙。谢谢你!
我的选择查询正在返回一个数组...但我希望它返回一个对象
PHP:
$language = DB::select(select query here);
Run Code Online (Sandbox Code Playgroud)
我尝试->get()在之后添加,但似乎无法将其添加到数组中。
我正在尝试将一些图像压缩为用户选择的。到目前为止,我已经提出了一个压缩解决方案。我的问题是在我将相关数据压缩到 zip 文件后如何通过浏览器下载它。我尝试了不同的方法仍然不起作用。当我创建 zip 时,它存储在公共文件夹中。如何通过浏览器从那里下载 zip 文件?
这是我的代码
$photos = json_decode(Input::get('photos'));
$dir = time();
foreach ($photos as $file) {
/* Log::error(ImageHandler::getUploadPath(false, $file));*/
$imgName = last(explode('/', $file));
$path = public_path('downloads/' . $dir);
if (!File::exists($path)) {
File::makeDirectory($path, 0775, true);
}
ImageHandler::downloadFile($file, $path . '/' . $imgName);
}
$rootPath = realpath($path);
$zip_file = 'Photos.zip';
$public_dir = public_path();
$zip = new ZipArchive();
$zip->open($zip_file, ZipArchive::CREATE | ZipArchive::OVERWRITE);
/** @var SplFileInfo[] $files */
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($rootPath),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => …Run Code Online (Sandbox Code Playgroud)