本文整理汇总了PHP中Model::unguard方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::unguard方法的具体用法?PHP Model::unguard怎么用?PHP Model::unguard使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model
的用法示例。
在下文中一共展示了Model::unguard方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDeferredBinding
public function testDeferredBinding()
{
$sessionKey = uniqid('session_key', true);
Model::unguard();
$author = Author::create(['name' => 'Stevie']);
$phone = Phone::create(['number' => '0404040404']);
Model::reguard();
$phoneId = $phone->id;
// Deferred add
$author->phone()->add($phone, $sessionKey);
$this->assertNull($phone->author_id);
$this->assertNull($author->phone);
$this->assertEquals(0, $author->phone()->count());
$this->assertEquals(1, $author->phone()->withDeferred($sessionKey)->count());
// Commit deferred
$author->save(null, $sessionKey);
$phone = Phone::find($phoneId);
$this->assertEquals(1, $author->phone()->count());
$this->assertEquals($author->id, $phone->author_id);
$this->assertEquals('0404040404', $author->phone->number);
// New session
$sessionKey = uniqid('session_key', true);
// Deferred remove
$author->phone()->remove($phone, $sessionKey);
$this->assertEquals(1, $author->phone()->count());
$this->assertEquals(0, $author->phone()->withDeferred($sessionKey)->count());
$this->assertEquals($author->id, $phone->author_id);
$this->assertEquals('0404040404', $author->phone->number);
// Commit deferred
$author->save(null, $sessionKey);
$phone = Phone::find($phoneId);
$this->assertEquals(0, $author->phone()->count());
$this->assertNull($phone->author_id);
$this->assertNull($author->phone);
}
示例2: testDeferredBinding
public function testDeferredBinding()
{
$sessionKey = uniqid('session_key', true);
Model::unguard();
$author = Author::create(['name' => 'Stevie']);
$post = Post::create(['title' => "First post", 'description' => "Yay!!"]);
Model::reguard();
$postId = $post->id;
// Deferred add
$author->posts()->add($post, $sessionKey);
$this->assertNull($post->author_id);
$this->assertEmpty($author->posts);
$this->assertEquals(0, $author->posts()->count());
$this->assertEquals(1, $author->posts()->withDeferred($sessionKey)->count());
// Commit deferred
$author->save(null, $sessionKey);
$post = Post::find($postId);
$this->assertEquals(1, $author->posts()->count());
$this->assertEquals($author->id, $post->author_id);
$this->assertEquals(['First post'], $author->posts->lists('title'));
// New session
$sessionKey = uniqid('session_key', true);
// Deferred remove
$author->posts()->remove($post, $sessionKey);
$this->assertEquals(1, $author->posts()->count());
$this->assertEquals(0, $author->posts()->withDeferred($sessionKey)->count());
$this->assertEquals($author->id, $post->author_id);
$this->assertEquals(['First post'], $author->posts->lists('title'));
// Commit deferred
$author->save(null, $sessionKey);
$post = Post::find($postId);
$this->assertEquals(0, $author->posts()->count());
$this->assertNull($post->author_id);
$this->assertEmpty($author->posts);
}
示例3: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
$this->call(UserTableSeeder::class);
$this->call(IssueTableSeeder::class);
Model::reguard();
}
示例4: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
// Add to customer table
DB::table('customer')->insert([['name' => 'dasdsadasdsad', 'contactNumber' => '+639053343746', 'isSuspended' => false, 'created_at' => time(), 'updated_at' => time()], ['name' => 'asfdvds', 'contactNumber' => '+639053343746', 'isSuspended' => false, 'created_at' => time(), 'updated_at' => time()], ['name' => 'erqr', 'contactNumber' => '+639053343746', 'isSuspended' => false, 'created_at' => time(), 'updated_at' => time()], ['name' => 'xcvcxv', 'contactNumber' => '+639053343746', 'isSuspended' => false, 'created_at' => time(), 'updated_at' => time()], ['name' => 'yutu', 'contactNumber' => '+639053343746', 'isSuspended' => false, 'created_at' => time(), 'updated_at' => time()], ['name' => 'hjhgk', 'contactNumber' => '+639053343746', 'isSuspended' => false, 'created_at' => time(), 'updated_at' => time()], ['name' => 'xczcxzc', 'contactNumber' => '+639053343746', 'isSuspended' => false, 'created_at' => time(), 'updated_at' => time()], ['name' => 'wqeqweqwe', 'contactNumber' => '+639053343746', 'isSuspended' => false, 'created_at' => time(), 'updated_at' => time()], ['name' => 'adsdadadppp', 'contactNumber' => '+639053343746', 'isSuspended' => false, 'created_at' => time(), 'updated_at' => time()], ['name' => 'hgfdjfsndadsf', 'contactNumber' => '+639053343746', 'isSuspended' => false, 'created_at' => time(), 'updated_at' => time()]]);
Model::reguard();
}
示例5: testDeferredBinding
public function testDeferredBinding()
{
$sessionKey = uniqid('session_key', true);
Model::unguard();
$author = Author::create(['name' => 'Stevie']);
$event = EventLog::create(['action' => "user-created"]);
Model::reguard();
$eventId = $event->id;
// Deferred add
$author->event_log()->add($event, $sessionKey);
$this->assertNull($event->related_id);
$this->assertEmpty($author->event_log);
$this->assertEquals(0, $author->event_log()->count());
$this->assertEquals(1, $author->event_log()->withDeferred($sessionKey)->count());
// Commit deferred
$author->save(null, $sessionKey);
$event = EventLog::find($eventId);
$this->assertEquals(1, $author->event_log()->count());
$this->assertEquals($author->id, $event->related_id);
$this->assertEquals(['user-created'], $author->event_log->lists('action'));
// New session
$sessionKey = uniqid('session_key', true);
// Deferred remove
$author->event_log()->remove($event, $sessionKey);
$this->assertEquals(1, $author->event_log()->count());
$this->assertEquals(0, $author->event_log()->withDeferred($sessionKey)->count());
$this->assertEquals($author->id, $event->related_id);
$this->assertEquals(['user-created'], $author->event_log->lists('action'));
// Commit deferred (model is deleted as per definition)
$author->save(null, $sessionKey);
$event = EventLog::find($eventId);
$this->assertEquals(0, $author->event_log()->count());
$this->assertNull($event);
$this->assertEmpty($author->event_log);
}
示例6: testDeferredBinding
public function testDeferredBinding()
{
$sessionKey = uniqid('session_key', true);
Model::unguard();
$post = Post::make(['title' => "First post"]);
$author = Author::create(['name' => 'Stevie']);
Model::reguard();
// Deferred add
$post->author()->add($author, $sessionKey);
$this->assertNull($post->author_id);
$this->assertNull($post->author);
$this->assertEquals(0, $post->author()->count());
$this->assertEquals(1, $post->author()->withDeferred($sessionKey)->count());
// Commit deferred
$post->save(null, $sessionKey);
$this->assertEquals(1, $post->author()->count());
$this->assertEquals($author->id, $post->author_id);
$this->assertEquals('Stevie', $post->author->name);
// New session
$sessionKey = uniqid('session_key', true);
// Deferred remove
$post->author()->remove($author, $sessionKey);
$this->assertEquals(1, $post->author()->count());
$this->assertEquals(0, $post->author()->withDeferred($sessionKey)->count());
$this->assertEquals($author->id, $post->author_id);
$this->assertEquals('Stevie', $post->author->name);
// Commit deferred
$post->save(null, $sessionKey);
$this->assertEquals(0, $post->author()->count());
$this->assertNull($post->author_id);
$this->assertNull($post->author);
}
示例7: testDeferredBinding
public function testDeferredBinding()
{
$sessionKey = uniqid('session_key', true);
Model::unguard();
$author = Author::create(['name' => 'Stevie']);
$meta = Meta::create(['meta_title' => 'Comment', 'meta_description' => 'Social', 'meta_keywords' => 'startup', 'canonical_url' => 'http://facebook.com/search/users', 'redirect_url' => 'http://facebook.com', 'robot_index' => 'index', 'robot_follow' => 'follow']);
Model::reguard();
$metaId = $meta->id;
// Deferred add
$author->meta()->add($meta, $sessionKey);
$this->assertNull($meta->taggable_id);
$this->assertNull($author->meta);
$this->assertEquals(0, $author->meta()->count());
$this->assertEquals(1, $author->meta()->withDeferred($sessionKey)->count());
// Commit deferred
$author->save(null, $sessionKey);
$meta = Meta::find($metaId);
$this->assertEquals(1, $author->meta()->count());
$this->assertEquals($author->id, $meta->taggable_id);
$this->assertEquals('Comment', $author->meta->meta_title);
// New session
$sessionKey = uniqid('session_key', true);
// Deferred remove
$author->meta()->remove($meta, $sessionKey);
$this->assertEquals(1, $author->meta()->count());
$this->assertEquals(0, $author->meta()->withDeferred($sessionKey)->count());
$this->assertEquals($author->id, $meta->taggable_id);
$this->assertEquals('Comment', $author->meta->meta_title);
// Commit deferred
$author->save(null, $sessionKey);
$meta = Meta::find($metaId);
$this->assertEquals(0, $author->meta()->count());
$this->assertNull($meta->taggable_id);
$this->assertNull($author->meta);
}
示例8: testSetRelationValueBelongsTo
public function testSetRelationValueBelongsTo()
{
Model::unguard();
$post = Post::create(['title' => "First post", 'description' => "Yay!!"]);
$author1 = Author::create(['name' => 'Stevie', 'email' => 'stevie@email.tld']);
$author2 = Author::create(['name' => 'Louie', 'email' => 'louie@email.tld']);
$author3 = Author::make(['name' => 'Charlie', 'email' => 'charlie@email.tld']);
Model::reguard();
// Set by Model object
$post->author = $author1;
$this->assertEquals($author1->id, $post->author_id);
$this->assertEquals('Stevie', $post->author->name);
// Set by primary key
$post->author = $author2->id;
$this->assertEquals($author2->id, $post->author_id);
$this->assertEquals('Louie', $post->author->name);
// Nullify
$post->author = null;
$this->assertNull($post->author_id);
$this->assertNull($post->author);
// Deferred
$post->author = $author3;
$this->assertEquals('Charlie', $post->author->name);
$this->assertNull($post->author_id);
$author3->save();
$this->assertEquals($author3->id, $post->author_id);
}
示例9: testGetRelationValue
public function testGetRelationValue()
{
Model::unguard();
$author = Author::create(['name' => 'Stevie']);
$event = EventLog::make(['action' => "user-created", 'related_id' => $author->id, 'related_type' => get_class($author)]);
Model::reguard();
$this->assertEquals([$author->id, get_class($author)], $event->getRelationValue('related'));
}
示例10: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
// $this->call(UserTableSeeder::class);
DB::table('users')->insert(['first_name' => 'Администратор', 'email' => 'admin@localhost.loc', 'password' => bcrypt('adminadmin')]);
DB::table('post_statuses')->insert([['name' => 'Неопубликован'], ['name' => 'На модерации'], ['name' => 'Опубликован']]);
DB::table('menuitem_types')->insert([['name' => 'Внутренняя ссылка'], ['name' => 'Внешняя ссылка'], ['name' => 'Маркер'], ['name' => 'Группа маркеров']]);
DB::table('administrators')->insert(['username' => 'admin', 'password' => bcrypt('adminadmin'), 'name' => 'Администратор']);
DB::table('marker_groups')->insert([['name' => 'Кухня'], ['name' => 'Блюдо'], ['name' => 'Дневной рацион']]);
Model::reguard();
}
示例11: testDeleteFlagSoftDeleteModel
public function testDeleteFlagSoftDeleteModel()
{
Model::unguard();
$user = SoftDeleteUser::create(['name' => 'Stevie', 'email' => 'stevie@email.tld']);
Model::reguard();
$user->avatar()->create(['data' => base_path() . '/tests/fixtures/plugins/database/tester/assets/images/avatar.png']);
$this->assertNotNull($user->avatar);
$avatarId = $user->avatar->id;
$user->delete();
$this->assertNotNull(FileModel::find($avatarId));
}
示例12: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
DB::table('users')->delete();
$users = array(['name' => 'Yuvraj Singh', 'email' => 'yuvraj.cse@gmail.com', 'password' => Hash::make('secret')], ['name' => 'Subhankar Pramanik', 'email' => 'subhankar.pramanik@businessprodesigns.com', 'password' => Hash::make('secret')], ['name' => 'Soham Banik', 'email' => 'soham.banik@businessprodesigns.com', 'password' => Hash::make('secret')], ['name' => 'Prasenjit Ghosh', 'email' => 'prasenjit.ghosh@businessprodesigns.com', 'password' => Hash::make('secret')]);
// Loop through each user above and create the record for them in the database
foreach ($users as $user) {
User::create($user);
}
Model::reguard();
}
示例13: testCommitBinding
public function testCommitBinding()
{
$sessionKey = uniqid('session_key', true);
DeferredBinding::truncate();
Model::unguard();
$author = Author::make(['name' => 'Stevie']);
$post = Post::create(['title' => "First post"]);
Model::reguard();
$author->posts()->add($post, $sessionKey);
$this->assertEquals(1, DeferredBinding::count());
$author->commitDeferred($sessionKey);
$this->assertEquals(0, DeferredBinding::count());
}
示例14: seedSampleTree
public function seedSampleTree()
{
Model::unguard();
$orange = CategoryNested::create(['name' => 'Category Orange', 'description' => 'A root level test category']);
$autumn = $orange->children()->create(['name' => 'Autumn Leaves', 'description' => 'Disccusion about the season of falling leaves.']);
$autumn->children()->create(['name' => 'September', 'description' => 'The start of the fall season.']);
$october = $autumn->children()->create(['name' => 'October', 'description' => 'The middle of the fall season.']);
$autumn->children()->create(['name' => 'November', 'description' => 'The end of the fall season.']);
$orange->children()->create(['name' => 'Summer Breeze', 'description' => 'Disccusion about the wind at the ocean.']);
$green = CategoryNested::create(['name' => 'Category Green', 'description' => 'A root level test category']);
$green->children()->create(['name' => 'Winter Snow', 'description' => 'Disccusion about the frosty snow flakes.']);
$green->children()->create(['name' => 'Spring Trees', 'description' => 'Disccusion about the blooming gardens.']);
Model::reguard();
}
示例15: testDeleteFlagDeleteModel
public function testDeleteFlagDeleteModel()
{
Model::unguard();
$user = User::create(['name' => 'Stevie', 'email' => 'stevie@email.tld']);
Model::reguard();
$this->assertEmpty($user->photos);
$user->photos()->create(['data' => base_path() . '/tests/fixtures/plugins/database/tester/assets/images/avatar.png']);
$user->reloadRelations();
$this->assertNotEmpty($user->photos);
$photo = $user->photos->first();
$this->assertNotNull($photo);
$photoId = $photo->id;
$user->delete();
$this->assertNull(FileModel::find($photoId));
}