예제 #1
0
 public function testDeleteWithRelations()
 {
     // one-to-many, many-to-many
     App\Post::find(1)->deleteWithRelations();
     self::assertEquals(App\Post::where('id', 1)->count(), 0);
     self::assertEquals(App\Comment::where('post_id', 1)->count(), 0);
     self::assertEquals(DB::table('lv_post_tag')->where('post_id', 1)->count(), 0);
     // one-to-one
     App\Post::getDeleteDescriptor()->removeDescription('comments');
     App\Comment::getDeleteDescriptor()->add('post');
     App\Comment::find(4)->deleteWithRelations();
     self::assertEquals(App\Comment::where('id', 4)->count(), 0);
     self::assertEquals(App\Post::where('id', 2)->count(), 0);
     // db rollback
     $this->rollback();
 }
예제 #2
0
        var_dump($faker->firstName . ' ' . $faker->lastName);
    }
});
/*********************************************************************************/
Route::post('validation', function () {
    $rules = array('name' => 'required', 'link' => 'required|url', 'password' => 'required|min:8', 'password-repeat' => 'required|same:password');
    $validator = Validator::make(Input::all(), $rules);
    if ($validator->fails()) {
        return Redirect::to('home')->withInput()->withErrors($validator->messages());
    }
    return 'Form was submitted';
});
/***********************************************************************************/
Route::get('comment', function () {
    // Grabbing the article of a particular comment
    $article = App\Comment::find(7)->article;
    dd($article->title);
    // Grabbing the comments for a particular article
    $comments = App\Article::find(4)->comments;
    //->where('body', '>', 50)->get();
    foreach ($comments as $comment) {
        var_dump($comment->body);
    }
});
Route::get('article2', function () {
    /*
    	DELETING ARTICLES
    */
    // deleting multiple articles
    $victims = App\Article::where('id', '<', 3);
    $victims->delete();