假设我有这个:
//controllers/BlogController.php
$data["post"] = $post = Blog::recent_post();
$data["posts_related"] = Blog::posts_related($post->category_id,5);
return View::make('blog.home', $data);
//views/sidebars/related.blade.php
@foreach($posts_related as $r)
<p>{{ $r->name }}</p>
@endforeach
//views/blog/home.blade.php
@include('sidebars.related')
Run Code Online (Sandbox Code Playgroud)
我的问题是,我怎么能转移:
$data["posts_related"] = Blog::posts_related($post->category_id,5);
Run Code Online (Sandbox Code Playgroud)
对于视图作曲家来说,因为我似乎无法将参数传递给视图作曲家,但我无法确定.
我感谢任何帮助!
我已经为Laravel 4安装了TwigBridge,我正在尝试调整一些我已经从Blade到Twig的模板.
我想在视图的顶部显示一些验证错误.
我在Blade中有以下内容(工作正常):
@if (isset($errors))
@foreach ($errors->all() as $error)
<p>{{ $error }}</p>
@endforeach
@endif
Run Code Online (Sandbox Code Playgroud)
我试图将它转换为Twig,但没有显示任何内容.
{% if errors %}
{% for error in errors %}
<p>{{ error }}</p>
{% endfor %}
{% endif %}
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试:
{{ errors }}
Run Code Online (Sandbox Code Playgroud)
我确实得到了一些输出:
{"name":["名称字段是必填项."]}
为了让它发挥作用,我需要改变什么?
任何建议表示赞赏
谢谢
从所有教程中,我应该能够授权用户然后跳转到任何其他页面,并且登录是持久的.但是,这不起作用.
自定义编译的PHP LAMP堆栈.应用程序存储是可写的.
与教程的唯一区别是我使用的是电子邮件而不是用户名. http://laravelbook.com/laravel-user-authentication/ http://codehappy.daylerees.com/authentication
会话工作,因为我能够将var存储到会话并在不同的页面上读取它.
models/User.php(股票)
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('password');
/**
* Get the unique identifier for the user.
*
* @return mixed
*/
public function getAuthIdentifier()
{
echo $this->getKey();
return $this->getKey();
} …Run Code Online (Sandbox Code Playgroud) 我有一个名为'标题'的表,我将添加软删除,但它还有其他几个表引用这个'标题'表:
目前,如果我删除标题,它将自动从标题详细信息中删除所有其他引用的表.
所以,如果我添加了一个软删除的"图书"表时删除执行会它,然后做一个对软删除"标题"表,但将删除引用的表的细节?或者它会忽略onDelete Cascade请求并保留引用的数据吗?
如果第一个选项那么我需要添加$ table-> softDeletes(); 到所有表格参考.以及添加受保护的$ softDelete = true; 对他们的模特?
请帮我使用Laravel4进行LDAP身份验证.
我的配置总是返回false
我有这样的auth.php:
<?php
return array(
/*
|--------------------------------------------------------------------------
| Default Authentication Driver
|--------------------------------------------------------------------------
|
| This option controls the authentication driver that will be utilized.
| This driver manages the retrieval and authentication of the users
| attempting to get access to protected areas of your application.
|
| Supported: "database", "eloquent"
|
*/
//'driver' => 'eloquent',
'driver' => 'ldap',
/*
|--------------------------------------------------------------------------
| Authentication Model
|--------------------------------------------------------------------------
|
| When using the "Eloquent" authentication driver, we need to know …Run Code Online (Sandbox Code Playgroud) 如何在Laravel Controller中使用私有变量,并在两个方法之间共享该变量值.(将其设置为一个用于另一个).
我正在寻找一种方法将Laravel/Eloquent数据库查询的结果映射到自定义类,而不是默认的Eloquent类.
Laravel/Eloquent是否包含任何内置设施?如果没有,是否有合适的地方"挂钩"到结果生成代码并进行必要的映射?
举个例子,这大致是我想要实现的目标:
class User extends Eloquent {}
class MyUser
{
protected $name;
public function getName() {
return $this->name;
}
public function setName($name) {
$this->name = $name;
return $this;
}
}
$users = User::all();
// $users should now contain an array of MyUser instances
Run Code Online (Sandbox Code Playgroud)
动机/问题的原因
这个问题背后的动机是找到一种方法,查询可以生成完全独立于框架的对象或对象数组.这是因为有问题的Laravel应用程序需要能够将其结果传递给其他非Laravel系统,因此Plain Old PHP对象(例如MyUser)最有意义.
我正在尝试在Laravel项目中设置PHPunit(使用Vagrant和VirtualBox在Linux VM中运行).我已经添加了PHPUnit来composer.json并运行composer install和composer update,却没有什么工作.phpunit从命令行运行什么都不做.(也不php phpunit或php phpunit.phar).
如何让PHPunit运行我的测试?
有没有办法删除添加的模型观察者
$model->observe(new ObserverObject)
Run Code Online (Sandbox Code Playgroud)
也许像
$model->observers['ObserverObject']->remove()
Run Code Online (Sandbox Code Playgroud)
谢谢
I`m use
public function getImages($array_symbols_id){
$array_images = DB::table('photo')
->whereIn('photo_symbol_id', $array_symbols_id)
->where('photo_moderation_id','2')
->orderByRaw('RAND()')
->get(['photo_id', 'photo_src', 'photo_symbol_id']);
Run Code Online (Sandbox Code Playgroud)
then try
$array = array();
foreach ($array_symbols_id as $id) {
$array[] = $array_images->where('photo_symbol_id', $id)->first()->photo_src;
}
Run Code Online (Sandbox Code Playgroud)
but i have exception Call to a member function where() on array.
Why DB::table returns an array but not a collection?
laravel v5.0.35