/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     factory('App\\Photo')->create(['blog_post_id' => App\BlogPost::findOrFail(2)->id]);
     factory('App\\Photo')->create(['blog_post_id' => App\BlogPost::findOrFail(2)->id]);
     factory('App\\Photo')->create(['blog_post_id' => App\BlogPost::findOrFail(1)->id]);
     factory('App\\Photo')->create(['blog_post_id' => App\BlogPost::findOrFail(6)->id]);
     factory('App\\Photo')->create(['blog_post_id' => App\BlogPost::findOrFail(4)->id]);
     factory('App\\Photo')->create(['blog_post_id' => App\BlogPost::findOrFail(8)->id]);
 }
Exemple #2
0
Route::post('auth/register', 'Auth\\AuthController@postRegister');
// FRIENDSHIP ROUTES
Route::get('user/{user}/addFriend', ['as' => 'addFriend', 'uses' => 'UserController@addFriend']);
Route::get('friend/{user}/approveFriend', ['as' => 'approveFriend', 'uses' => 'FriendController@approveFriend']);
Route::get('friend/{user}/denyFriend', ['as' => 'denyFriend', 'uses' => 'FriendController@denyFriend']);
// RESOURCE ROUTES...
Route::resource('user', 'UserController', ['except' => ['create', 'store']]);
Route::resource('blog', 'BlogController', ['except' => ['create', 'delete', 'store']]);
Route::resource('blog.blogPost', 'BlogPostController');
Route::get('/blogPost', ['uses' => 'BlogPostController@index', 'as' => 'blogPosts.index']);
Route::resource('blog.blogPost.photo', 'PhotoController', ['except' => ['index', 'show', 'create']]);
Route::get('/', ['uses' => 'PagesController@index']);
// ROUTE MODEL BINDINGS...
Route::bind('user', function ($value) {
    return App\User::with('blog')->findOrFail($value);
});
Route::bind('blog', function ($value) {
    // de-hyphenate the blog name
    $value = getNameForThisUrl($value);
    // return the Blog instance with the name of $value, with blogPosts
    return App\Blog::with('blogPost')->where('name', $value)->firstOrFail();
});
Route::bind('blogPost', function ($value) {
    // de-hyphenate the blog name
    $value = getNameForThisUrl($value);
    // return the Blog instance with the name of $value, with blogPosts
    return App\BlogPost::with('photo')->where('title', $value)->firstOrFail();
});
Route::bind('photo', function ($value) {
    return App\Photo::findOrFail($value);
});
<?php

$factory->define(App\User::class, function (Faker\Generator $faker) {
    return ['name' => $faker->name, 'email' => $faker->email, 'password' => bcrypt(str_random(10)), 'remember_token' => str_random(10), 'hometown' => $faker->city, 'brief_description' => $faker->paragraph(5), 'age' => $faker->numberBetween(20, 50), 'profile_pic' => $faker->imageUrl(600, 450, 'people', true)];
});
$factory->define(App\Blog::class, function (Faker\Generator $faker) {
    return ['name' => $faker->sentencenoperiod($nbWords = 4), 'tagline' => $faker->sentencenoperiod($nbWords = 13), 'user_id' => factory('App\\User')->create()->id];
});
$factory->define(App\BlogPost::class, function (Faker\Generator $faker) {
    return ['published_at' => Carbon\Carbon::now(), 'title' => $faker->sentencenoperiod(8), 'tagline' => $faker->sentencenoperiod(13), 'content' => $faker->paragraphs(4, true), 'featured_image' => $faker->imageUrl(600, 350, 'city', true), 'blog_id' => factory('App\\Blog')->create()->id];
});
$factory->defineAs(App\BlogPost::class, 'extraPosts', function ($faker) {
    return ['published_at' => Carbon\Carbon::now(), 'title' => $faker->sentencenoperiod($nbWords = 8), 'tagline' => $faker->sentencenoperiod($nbWords = 13), 'content' => $faker->paragraphs($nb = 3, true), 'featured_image' => $faker->imageUrl(600, 350, 'city', true), 'blog_id' => App\Blog::findOrFail($faker->numberBetween($min = 1, $max = 10))->id];
});
$factory->define(App\Photo::class, function (Faker\Generator $faker) {
    return ['path' => $faker->imageUrl(800, 640, 'city', true), 'thumbnail_path' => $faker->imageUrl(800, 640, 'city', true), 'blog_post_id' => factory('App\\BlogPost')->create()->id];
});
$factory->defineAs(App\Photo::class, 'extraPhotos', function ($faker) {
    return ['path' => $faker->imageUrl(800, 640, 'city', true), 'thumbnail_path' => $faker->imageUrl(800, 640, 'city', true), 'blog_post_id' => App\BlogPost::findOrFail($faker->numberBetween($min = 1, $max = 10))->id];
});