/**
  *  Add a Post
  */
 public function postAdd()
 {
     $data = \Input::all();
     $post = new \App\Post($data);
     // TODO: validation
     $post->save();
     return redirect('admin/posts')->with('status', "Post {$post->id} Added");
 }
Beispiel #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['title' => 'required|min:10|max:1000', 'post' => 'required|min:10|max:10000']);
     $post = new \App\Post();
     $post->title = $request->title;
     $post->post = $request->post;
     $post->user_id = 1;
     $post->save();
 }
Beispiel #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $post = new \App\Post();
     $post->user_id = Auth::user()->id;
     $post->title = $request->title;
     $post->post_description = $request->post_description;
     $post->save();
     return $post;
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $post = new \App\Post();
     $post->title = $request->title;
     $post->post_content = $request->post_content;
     $post->subbreddit_id = $request->subbreddit_id;
     $post->user_id = \Auth::user()->id;
     $post->url = $request->url;
     $post->save();
     return $post;
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     $content = "この文章はダミーです。あいうえおかきくけこ。この文章はダミーです。あいうえおかきくけこ。この文章はダミーです。あいうえおかきくけこ。この文章はダミーです。あいうえおかきくけこ。この文章はダミーです。あいうえおかきくけこ。この文章はダミーです。あいうえおかきくけこ。この文章はダミーです。あいうえおかきくけこ。";
     $commentdammy = "コメントダミー。コメントダミー。コメントダミー。";
     for ($i = 1; $i <= 10; $i++) {
         $post = new App\Post();
         $post->title = "{$i} 番目の投稿";
         $post->content = $content;
         $post->cat_id = 1;
         $post->save();
         $maxComments = mt_rand(3, 15);
         for ($j = 0; $j <= $maxComments; $j++) {
             $comment = new App\Comment();
             $comment->commenter = '名無しさん';
             $comment->comment = $commentdammy;
             $post->comments()->save($comment);
             $post->increment('comment_count');
         }
     }
     // Category
     $cat1 = new App\Category();
     $cat1->name = "ニュース";
     $cat1->save();
     $cat2 = new App\Category();
     $cat2->name = "食品";
     $cat2->save();
     $cat3 = new App\Category();
     $cat3->name = "電化製品";
     $cat3->save();
     $cat4 = new App\Category();
     $cat4->name = "テレビ";
     $cat4->save();
     $cat5 = new App\Category();
     $cat5->name = "文化";
     $cat5->save();
     $cat6 = new App\Category();
     $cat6->name = "映画";
     $cat6->save();
     $cat7 = new App\Category();
     $cat7->name = "スポーツ";
     $cat7->save();
     $cat8 = new App\Category();
     $cat8->name = "ゲーム";
     $cat8->save();
     $cat9 = new App\Category();
     $cat9->name = "社会";
     $cat9->save();
     $cat10 = new App\Category();
     $cat10->name = "教育";
     $cat10->save();
 }
Beispiel #6
0
 public function savePost(NewPostRequest $request)
 {
     // Validate and store the blog post...
     $arreglo = array($request->input("title"), $request->input("content"), Carbon::now());
     $post = new \App\Post();
     $post->title = $request->input("title");
     $post->content = $request->input("content");
     $post->published_at = date('Y-m-d H:i:s');
     $post->category_id = $request->input("category");
     $post->save();
     return $imageInfo;
     //return Redirect::to('blog')->withInput()->with('success', 'Artículo creado exitosamente.');
 }
Beispiel #7
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     for ($i = 0; $i < 10; $i++) {
         $faker = Faker\Factory::create();
         $post = new App\Post();
         $post->name = 'Dummy Post ' . $i;
         $post->slug = 'dummy_post_' . $i;
         $post->copy = $faker->realText($maxNbChars = 2000, $indexSize = 4);
         $post->photo = $faker->imageUrl($width = 400, $height = 300);
         $post->created_at = new dateTime();
         $post->updated_at = new dateTime();
         $post->save();
     }
 }
 public function postPublish(Request $request)
 {
     $this->validate($request, ['title' => 'required|min:2', 'text' => 'required|min:5', 'date' => 'required|date_format:n/j/Y']);
     $user = \Auth::user();
     $userId = $user->id;
     $date = $request->date;
     $dateFormatted = Carbon::createFromFormat('n/j/Y', $date);
     $post = new \App\Post();
     $post->title = $request->title;
     $post->date = $dateFormatted;
     $post->text = $request->text;
     $post->user_id = $userId;
     $post->save();
     \Session::flash('flash_message', 'Your post was published!');
     return redirect('/blog');
 }
Beispiel #9
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     factory(App\User::class, 50)->create()->each(function ($user) {
         // Each user will create 5 posts
         for ($i = 0; $i < 5; $i++) {
             $user->posts()->save(factory(App\Post::class)->make());
         }
         // Each user will favorite 2 posts
         for ($i = 0; $i < 2; $i++) {
             // Store a random post_id
             $temp = rand(1, App\Post::all()->count());
             // If the loop has not run before assigned a value to $lastTemp
             if ($i == 0) {
                 $lastTemp = 0;
             }
             // To prevent overlap, keep generating a new random post_id until a new post_id is generated
             while ($temp == $lastTemp) {
                 $temp = rand(1, App\Post::all()->count());
             }
             // Now that a new post_id has been generated, favorite the post
             $user->likes()->attach($temp);
             // Store the post_id to be rechecked in case the loop runs again
             $lastTemp = $temp;
         }
     });
 }
Beispiel #10
0
 public function postAddPost(Request $request)
 {
     $this->validate($request, ['title' => 'required|min:5', 'description' => 'required|min:25', 'file' => 'required|image']);
     $post = new \App\Post();
     $post->title = $request->title;
     $post->description = $request->description;
     $post->link_to_video = $request->link_to_video;
     $file = $request->file('file');
     $file_name = $file->getClientOriginalName();
     \Storage::disk('local')->put($file_name, \File::get($file));
     $post->link_to_image = 'uploads/' . $file_name;
     $img = Image::make($post->link_to_image)->resize(560, 315);
     $img->save();
     $post->save();
     \Session::flash('flash_message', 'Your Post was added!');
     return redirect('/addPost');
 }
 public function run()
 {
     DB::table('posts')->truncate();
     $faker = Faker\Factory::create('zh_TW');
     foreach (range(1, 10) as $number) {
         App\Post::create(['title' => $faker->sentence, 'sub_title' => $faker->sentence, 'content' => $faker->paragraph, 'is_hot' => rand(0, 1), 'created_at' => Carbon\Carbon::now()->addDays($number), 'updated_at' => Carbon\Carbon::now()->addDays($number)]);
     }
 }
Beispiel #12
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     App\User::truncate();
     App\Post::truncate();
     App\Phone::truncate();
     $this->call(UserTableSeeder::class);
     Model::reguard();
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // $this->call(UserTableSeeder::class);
     factory(App\User::class, 50)->create()->each(function ($user) {
         $user->posts()->save(factory(App\Post::class)->make());
         $post = App\Post::find(rand(1, App\Post::all()->count()));
         $user->userPosts()->attach($post);
     });
 }
Beispiel #14
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     factory(App\Comment::class, 500)->create()->each(function ($comment) {
         $comment->user()->associate(App\User::random()->first());
         $comment->post()->associate(App\Post::random()->first());
         // TODO: Seed parent/child comment relationship
         $comment->save();
     });
 }
Beispiel #15
0
 /**
  * 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);
     Model::unguard();
     App\User::truncate();
     App\Post::truncate();
     // Comment::truncate();
     factory(App\Post::class, 10)->create();
     Model::reguard();
 }
Beispiel #17
0
 public function run()
 {
     // Uncomment the below to wipe the table clean before populating
     DB::table('comments')->delete();
     $posts = App\Post::all();
     $users = App\User::all();
     for ($i = 1; $i <= 3; $i++) {
         $comments = array(['body' => "Nice post!", 'user_id' => $i, 'commentable_id' => $i * 8 % 11 + 1, 'commentable_type' => 'App\\Post', 'created_at' => new DateTime(), 'updated_at' => new DateTime()], ['body' => "Agreed.", 'user_id' => $i, 'commentable_id' => $i * 8 % 11 + 2, 'commentable_type' => 'App\\Post', 'created_at' => new DateTime(), 'updated_at' => new DateTime()], ['body' => "No way!", 'user_id' => $i, 'commentable_id' => $i * 8 % 11 + 3, 'commentable_type' => 'App\\Post', 'created_at' => new DateTime(), 'updated_at' => new DateTime()], ['body' => "I guess...", 'user_id' => $i, 'commentable_id' => $i * 8 % 11 + 4, 'commentable_type' => 'App\\Post', 'created_at' => new DateTime(), 'updated_at' => new DateTime()]);
         // Uncomment the below to run the seeder
         DB::table('comments')->insert($comments);
     }
 }
Beispiel #18
0
 /**
  * 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()
 {
     Model::unguard();
     // $this->call(UserTableSeeder::class);
     App\Category::create(['title' => 'Public']);
     App\Category::create(['title' => 'Private']);
     App\Category::create(['title' => 'Family']);
     $faker = Faker\Factory::create();
     foreach (range(1, 100) as $index) {
         App\Post::create(['title' => $faker->realText(30, 2), 'content' => $faker->realText(100, 2), 'category_id' => App\Category::all()->random()->id]);
     }
     Model::reguard();
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create();
     foreach (range(1, 3) as $i) {
         App\User::create(['name' => $faker->name, 'email' => $faker->email, 'password' => bcrypt('password')]);
     }
     foreach (range(1, 3) as $i) {
         App\Category::create(['title' => $faker->word]);
     }
     foreach (range(1, 5) as $i) {
         App\Post::create(['title' => $faker->sentence, 'content' => $faker->paragraph, 'category_id' => rand(1, 3), 'user_id' => rand(1, 3)]);
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //factory(PostHasTag::class, 50)->create();
     $posts = App\Post::all();
     $tags = App\Tag::all();
     foreach ($posts as $post) {
         $list = [];
         foreach ($tags as $tag) {
             rand(0, 5) == 0 && count($list) < 10 ? $list[] = $tag->id : null;
         }
         $post->tags()->sync($list);
     }
 }
Beispiel #22
0
 /**
  * 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()));
     });
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $fake = Faker\Factory::create();
     App\Post::truncate();
     foreach ($variable as $key) {
         # code...
     }
     // \Auth::user()->posts()->create(new \App\Post([
     // 	'title' => str_random(20),
     // 	'content' => str_random(500),
     // 	'published_at' = \Carbon\Carbon::now();
     // ]));
     // Post::create([
     // 	'title' => str_random(20),
     // ]);
 }
Beispiel #24
0
<?php

get('/', ['middleware' => ['cache.fetch', 'cache.put'], 'uses' => 'HomeController@home']);
get('/articles/{slug}', ['as' => 'articles.show', 'uses' => 'HomeController@showArticle']);
get('/user/{username}/articles', ['middleware' => ['cache.fetch', 'cache.put'], 'uses' => function ($username) {
    return 'article of ' . $username;
}]);
get('auth/github', 'Auth\\AuthController@redirectToProvider');
get('auth/github/callback', 'Auth\\AuthController@handleProviderCallback');
Route::group(['middleware' => 'auth'], function () {
    get('auth/logout', function () {
        \Auth::logout();
        return redirect('/');
    });
    resource('posts', 'PostController');
});
get('test/search', function () {
    $keyword = \Request::get('keyword') || 'lorem';
    // Match any fields
    $posts = App\Post::search($keyword)->paginate();
    dd($posts);
    // Match all fields
    // Article::search($keyword, true)->paginate();
});
get('test/transaction', function () {
    \DB::transaction(function () {
        App\Post::findOrFail(8);
        $foo = App\Post::find(6)->delete();
    });
});
 public function run()
 {
     App\Post::truncate();
     factory(App\Post::class, 20)->create();
 }
<?php

/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
// User Factory
$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)];
});
// Post Factory
$factory->define(App\Post::class, function (Faker\Generator $faker) {
    return ['title' => $faker->sentence(), 'short_story' => $faker->text(500), 'full_story' => $faker->text(2000), 'image' => $faker->imageUrl($width = 640, $height = 480), 'user_id' => App\User::all()->random(1)->id];
});
// Comment Factory
$factory->define(App\Comment::class, function (Faker\Generator $faker) {
    return ['comment' => $faker->text(rand(100, 1000)), 'post_id' => App\Post::all()->random(1)->id, 'user_id' => App\User::all()->random(1)->id];
});
Beispiel #27
0
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('demo/{group_urlname}', function ($group) {
    $client = DMS\Service\Meetup\MeetupKeyAuthClient::factory(['key' => env('MEETUP_API_KEY')]);
    $members = $client->getMembers(['group_urlname' => $group, 'fields' => 'bio']);
    $members = $members->toArray();
    // dd($membersArray[0]);
    return view('members', ['members' => $members, 'group' => $group]);
});
Route::get('/', function () {
    return view('welcome');
});
Route::get('about', 'PagesController@about');
Route::get('posts/create', 'PostsController@create');
Route::post('posts/create', 'PostsController@store');
Route::get('posts/{id}/{slug}', function ($id, $slug) {
    $post = App\Post::find($id);
    if ($post && $post->slug === $slug) {
        return $post;
    }
});
Beispiel #28
0
    echo "我现在" . $age . "岁!!!";
}]);
Route::get('blade', function () {
    return view('layouts.child');
});
Route::get('model', function () {
    $s = App\Staff::class;
    $r = $s::find(1);
    $rr = $r->photos;
    dump($rr);
});
Route::get('model2', function () {
    /*
     * 多态多关联
     * */
    $post = App\Post::find(1);
    dump($post->tags->toArray());
    $tag = App\Tag::find(1);
    dump($tag->posts->toArray());
});
/*
 * 关联查询
 * */
Route::get('gl', function () {
    //有评论的文章  或者对于这个 是  有飞机的航线
    //这个has获得的还是本表的内容 has只是个条件 不能获得子表内容
    $f = App\Flight::has('fly')->get();
    dump($f);
    //这个才是获得子表的结果
    $fly = App\Flight::find(1)->fly;
    dump($fly->toArray());
 public function testCanStoreAPost()
 {
     App\Post::create(['name' => 'Joe Bloggs', 'email' => '*****@*****.**', 'comment' => 'Lorem ipsum']);
     $this->seeInDatabase('posts', ['name' => 'Joe Bloggs']);
 }
Beispiel #30
0
<?php

/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
$factory->define(App\User::class, function (Faker\Generator $faker) {
    return ['username' => $faker->userName, 'email' => $faker->email, 'password' => bcrypt(str_random(10)), 'remember_token' => str_random(10)];
});
$factory->define(App\Category::class, function (Faker\Generator $faker) {
    return ['parent_id' => mt_rand(null, 5), 'name' => $faker->words(3, true), 'description' => $faker->words(5, true)];
});
$factory->define(App\Post::class, function (Faker\Generator $faker) {
    return ['category_id' => mt_rand(1, 100), 'user_id' => mt_rand(1, 10), 'title' => $faker->words(4, true), 'content' => join("\n\n", $faker->paragraphs(mt_rand(6, 20))), 'created_at' => $faker->dateTimeBetween('-1 month', '+3 days')];
});
$factory->define(App\PostImage::class, function (Faker\Generator $faker) {
    return ['post_id' => $faker->randomElement(App\Post::all()->lists('id')->toArray()), 'path' => $faker->imageUrl($width = 640, $height = 480, 'cats', true)];
});
$factory->define(App\State::class, function (Faker\Generator $faker) {
    return ['state' => $faker->state, 'state_abbr' => $faker->stateAbbr];
});
$factory->define(App\City::class, function (Faker\Generator $faker) {
    return ['state_id' => mt_rand(1, 5), 'city' => $faker->city];
});