/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $subbreddit = new \App\Subbreddit(); $subbreddit->user_id = \Auth::user()->id; $subbreddit->name = $request->name; $subbreddit->description = $request->description; $subbreddit->save(); return $subbreddit; }
/** * Store a newly created resource in storage. * Subbreddits have user_id, title, description * Fix: my subbreddits have title and not name!! * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $subbreddit = new \App\Subbreddit(); $subbreddit->user_id = \Auth::user()->id; // changing $request to \Auth:: $subbreddit->title = $request->title; // change name to title $subbreddit->description = $request->description; $subbreddit->save(); return $subbreddit; }
/** * Run the database seeds. * * @return void */ public function run() { factory(App\User::class, 50)->create()->each(function ($user) { $user->subbreddits()->save(factory(App\Subbreddit::class)->make()); $user->posts()->save(factory(App\Post::class)->make(['subbreddit_id' => rand(1, App\Subbreddit::all()->count())])); $user->comments()->save(factory(App\Comment::class)->make(['post_id' => rand(1, App\Post::all()->count())])); $user->comments()->save(factory(App\Comment::class)->make(['comment_id' => rand(1, App\Comment::all()->count())])); $user->subscribedSubbreddits()->attach(rand(1, App\Subbreddit::all()->count())); }); }
/** * Run the database seeds. * * @return void */ public function run() { // $this->call(UserTableSeeder::class); // change # to 10 for now factory(App\User::class, 10)->create()->each(function ($user) { $user->subbreddits()->save(factory(App\Subbreddit::class)->make()); $user->posts()->save(factory(App\Post::class)->make(['subbreddit_id' => rand(1, App\Subbreddit::all()->count())])); $user->comments()->save(factory(App\Comment::class)->make(['post_id' => rand(1, App\Post::all()->count())])); $user->comments()->save(factory(App\Comment::class)->make(['comment_id' => rand(1, App\Comment::all()->count())])); $user->subscribedSubbreddits()->attach(rand(1, App\Subbreddit::all()->count())); }); }
/** * Run the database seeds. * * @return void */ public function run() { factory(App\User::class, 50)->create()->each(function ($user) { // Each user will make 1 subbreddit $user->subbreddits()->save(factory(App\Subbreddit::class)->make()); // Each user will make 1 post on a random subbreddit $user->posts()->save(factory(App\Post::class)->make(['subbreddit_id' => rand(1, App\Subbreddit::all()->count())])); // Each user will leave a comment on a random post $user->comments()->save(factory(App\Comment::class)->make(['post_id' => rand(1, App\Post::all()->count())])); // Each user will leave a comment on a random comment $user->comments()->save(factory(App\Comment::class)->make(['comment_id' => rand(1, App\Comment::all()->count())])); // Each user will subscribe to 1 subbreddit $user->subscribedSubbreddits()->attach(rand(1, App\Subbreddit::all()->count())); }); }