在Liquid模板中调用items和array时,如何调用does not contain或not in array?
我需要将两个字段从整数更改为外键.如何构建我的迁移呢?
Schema::create('messages', function($table)
{
$table->increments('id');
$table->integer('sender');
$table->integer('recipient');
$table->string('title');
$table->longtext('body');
$table->timestamps();
$table->softDeletes();
$table->integer('regarding');
});
Run Code Online (Sandbox Code Playgroud)
我会改sender到sender_id,recipient到recipient_id和regarding到regarding_id.
阅读后,我一直在选择其他开发人员的大脑"脂肪模型,瘦身控制器"的概念:
大多数受访者正在使用我认为的胖控制器.
虽然这个主题已经出现在Stack Overflow上,但我还没有在实践中找到对该方法的详尽描述.
我正在有效地尝试定义用户(发送者和接收者)和消息之间的关系。
我的消息迁移是:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateMessagesTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
Schema::create('messages', function($t){
$t->increments('id');
$t->integer('sender_user_id')->unsigned();
$t->integer('recipient_user_id')->unsigned();
$t->string('subject');
$t->text('content');
$t->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
Schema::dropIfExists('messages');
}
}
Run Code Online (Sandbox Code Playgroud)
我的消息模型很简单:
<?php
class Message extends Eloquent{
// link to sender user id
public function from(){
return $this->hasOne('User', 'sender_user_id');
}
// link to recipient user id …Run Code Online (Sandbox Code Playgroud) 请解释为什么Laravel 4的示例测试失败了.
我的"/"路由重定向到我的routes.php文件中的"login".
(哦,我是RTFMed并搜索了几个网站,博客和内容.)
-sh-3.2$ phpunit
PHPUnit 4.0.7 by Sebastian Bergmann.
Configuration read from /home/dev/phpunit.xml
The Xdebug extension is not loaded. No code coverage will be generated.
F
Time: 83 ms, Memory: 13.50Mb
There was 1 failure:
1) ExampleTest::testBasicExample
Failed asserting that false is true.
/home/dev/app/tests/ExampleTest.php:14
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
-sh-3.2$
Run Code Online (Sandbox Code Playgroud)
这是ExampleTest.php中的代码
<?php
class ExampleTest extends TestCase {
/**
* A basic functional test example.
*
* @return void
*/
public function testBasicExample()
{
$crawler = $this->client->request('GET', …Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用PHP从我的数据库中呈现我的数据.我的while循环继续运行.
function makeCollection(){
$images = mysql_query("select file_id from images where collection_id = 1");
//returns file_id
$fileIds = mysql_fetch_array($images, MYSQL_NUM );
//get file ids from $images into array
while($fileIds != false){
echo($fileIds[0]);
}
}
Run Code Online (Sandbox Code Playgroud)
我有三个符合id = 1,2和3的对象(它是自动递增的).不应该循环迭代然后在第三个之后停止?它只是为无穷大写'1'.
我正在测试用户是否已经在数据库中有记录(d).
我的查询:
$userResults = Results::where('d','=',Input::get('d'))
->where('user','=',Input::get('user'),'AND')->get();
Run Code Online (Sandbox Code Playgroud)
带var_dump回报
object(Illuminate\Database\Eloquent\Collection)#333 (1) { ["items":protected]=> array(0) { } }
Run Code Online (Sandbox Code Playgroud)
当空时或结果数组(如果有).
如何测试对象isset?