public function __construct() { $this->postParser = new PostParser(); $this->tags = Tag::all(); $this->dificultyLevels = PostDificulty::all(); $this->posts = Post::all(); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { // dd('index'); $posts = Post::all(); $data = ['posts' => $posts, 'pageType' => 'All Post']; return view('posts.index', $data); }
public function like(Request $request) { onlyAllowPostRequest($request); $post_id = $request->input('id'); $user_id = $request->input('user'); /** * Dữ liệu trả về */ $response = new stdClass(); $likes = Like::all()->where('user_id', intval($user_id))->where('post_id', intval($post_id)); if ($likes->count() > 0) { $response->error = true; $response->error_msg = 'Bạn đã cảm ơn bài viết này!'; return response()->json($response); } $like = Like::create(['user_id' => $user_id, 'post_id' => $post_id]); $posts = Post::all()->where('id', intval($post_id)); if ($posts->count() == 0) { $response->error = true; $response->error_msg = 'Bạn đã cảm ơn bài viết này!'; return response()->json($response); } $count_like = intval($posts->first()->like); $count_like++; $p = DB::table('posts')->where('id', intval($post_id))->update(['like' => $count_like]); $response->error = false; $response->msg = 'Cảm ơn bạn!'; return response()->json($response); }
public function index() { if (\Request::ajax()) { return Post::all(); } return view('post.index'); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $category = Category::all(); $post = Post::all(); $data = array('post' => $post, 'category' => $category); return view('blog.index', $data); }
public static function posts($type = null, $data = null) { if ($type and $data) { return Post::where($type, $data)->get(); } return Post::all(); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { //return view('posts.index'); $posts = Post::all(); $data = ['posts' => $posts]; return view('posts.index', $data); }
/** * Execute the console command. * * @return mixed */ public function handle() { $posts = Post::all(['slug', 'updated_at']); $works = Work::all(['slug', 'updated_at']); $this->sitemap = new Sitemap(public_path('sitemap.xml')); $this->comment('Starting generating the Sitemap...'); // Home $this->addItem(config('app.url') . '/', 0.9); // Resume $this->addItem(config('app.url') . '/resume', 0.8); // Blog index $this->addItem(config('app.url') . '/blog', 0.8); // Works index $this->addItem(config('app.url') . '/works', 0.8); // @codeCoverageIgnoreStart // Blog posts foreach ($posts as $post) { $this->addItem(config('app.url') . '/blog/' . $post->slug, 0.7); } // Works items foreach ($works as $work) { $this->addItem(config('app.url') . '/works/' . $work->slug, 0.7); } // @codeCoverageIgnoreEnd $this->sitemap->write(); $this->comment('Sitemap generated successfully!'); }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker::Create(); foreach (range(1, 10) as $seededItem) { User::create(['first_name' => $faker->name, 'last_name' => $faker->name, 'password' => Hash::make('123456'), 'type' => false, 'sex' => $faker->boolean(), 'email' => $faker->email, 'date_of_birth' => $faker->date('Y-m-d')]); } $users = User::all()->lists('id')->toArray(); foreach (range(1, 100) as $seededItem) { Post::create(['user_id' => $faker->randomElement($users), 'body' => $faker->text, 'vote_count' => 0]); } $posts = Post::all()->lists('id')->toArray(); Comment::create(['user_id' => $faker->randomElement($users), 'body' => $faker->text, 'vote_count' => 0, 'parent_id' => null]); foreach (range(1, 100) as $seededItem) { Post_Vote::create(['user_id' => $faker->randomElement($users), 'post_id' => $faker->randomElement($posts), 'up' => $faker->boolean()]); Comment::create(['user_id' => $faker->randomElement($users), 'parent_id' => $faker->randomElement(Comment::all()->lists('id')->toArray()), 'post_id' => $faker->randomElement($posts), 'body' => $faker->text, 'vote_count' => 0]); Tag::create(['name' => $faker->text, 'private' => $faker->boolean()]); } $comments = Comment::all()->lists('id')->toArray(); $tags = Tag::all()->lists('id')->toArray(); foreach (range(1, 100) as $seededItem) { Comment_Vote::create(['user_id' => $faker->randomElement($users), 'comment_id' => $faker->randomElement($comments), 'up' => $faker->boolean()]); Tag_User::create(['user_id' => $faker->randomElement($users), 'tag_id' => $faker->randomElement($tags)]); Post_Tag::create(['tag_id' => $faker->randomElement($tags), 'post_id' => $faker->randomElement($posts)]); } }
public function index() { /** * Loading all posts. */ $posts = Post::all(); return view('blog.list', compact('posts')); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $user = Auth::user(); $posts = Post::all(); $data = $request->all(); Post::create(['content' => $data['content'], 'user_id' => $user->id]); return view('wall.index', compact('user', 'posts', 'data')); }
public function last($n = 3) { $posts = Post::all()->with(['tags' => function ($q) { $q->select('id', 'title'); }])->with(['comments' => function ($q) { $q->active()->select('active', 'post_id'); }])->orderBy('id', 'desc')->take($n)->get(); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $posts = Post::all(); if (!empty($posts)) { return response()->json(array('error' => false, 'posts' => $posts), 200); } else { return response()->json(array('error' => false, 'posts' => 'No posts found.'), 200); } }
public function posts(Request $req) { $content = []; $content['count'] = count(Post::all()); $content['page'] = 2; $content['per_page'] = 10; $content['data'] = Post::all(); return response($content, Response::HTTP_OK)->withHeaders(['Content-Type' => 'application/json', 'Access-Control-Allow-Origin' => '*']); }
public function getContent() { if (!Auth::check()) { return redirect('/login')->with('error', 'You need to be logged in!'); } $media = Post::all(); $comments = Comment::all(); return view('blog.content', compact('media', "comments")); }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('tags')->truncate(); factory(App\Tag::class, 10)->create(); $posts = Post::all(); foreach ($posts as $post) { $tags = Tag::orderByRaw('RAND()')->take(rand(1, 5))->get(['id']); $post->tags()->sync($tags); } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $post = new Post(); $input = $request->all(); $input['post_author'] = Auth::user()->id; $input['post_featured_image_url'] = "http://lorempixel.com/1000/500/fashion/" . random_int(1, 10); $post->fill($input)->save(); Session::flash('status', 'Your blog post has been created successfully!'); $posts = Post::all(); return view('posts.show', ['post' => $post]); }
public function get_admin_archive($type = false) { if ($type) { $posts = Post::where("type", "=", $type)->get(); } else { $posts = Post::all(); } $view = view::make("admin.posts.index"); $view->post_type = $type; $view->posts = $posts; return $view; }
public function index(Request $request) { /* $tag = $request->get('tag'); $data = $this->dispatch(new BlogIndexData($tag)); $layout = $tag ? Tag::layout($tag) : 'blog.layouts.index'; return view($layout, $data); */ $posts = Post::all(); return view('blog.index')->withPosts($posts)->withBy('All Authours'); }
/** * Seed the tags table */ public function run() { $max = 30; foreach (Post::all() as $post) { if ($post->id < $max) { $post->thumb_url = '/uploads/post/' . $post->id . '.jpg'; $post->save(); } else { // $post->thumb_url('/uploads/post/'.$post->id.'.jpg'); } } }
public function index() { // $posts = [ // 'Post 1' => 'Este o conteúdo do post 1', // 'Post 2' => 'Este o conteúdo do post 2', // 'Post 3' => 'Este o conteúdo do post 3', // 'Post 4' => 'Este o conteúdo do post 4', // 'Post 5' => 'Este o conteúdo do post 5', // ]; $posts = \App\Post::all(); return view('posts.index', compact('posts')); }
/** * Show the admin dashboard * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function dashboard(Request $request) { $posts = Post::all()->groupBy('post_type')->toArray(); if (!array_key_exists('post', $posts)) { $posts["post"] = []; } if (!array_key_exists('page', $posts)) { $posts["page"] = []; } $comments = Comment::all()->count(); return view('admin.dashboard', ['posts' => $posts, 'comment_count' => $comments]); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { // $notas = [ // 0 => 'Anotação 01', // 1 => 'Anotação 02', // 2 => 'Anotação 03', // 3 => 'Anotação 04' // ]; // return view('posts.home', compact('notas') ); $dados = \App\Post::all(); return view('posts.home', compact('dados')); }
public function table($data, $columnNames = null) { die(var_dump(\App\Post::all())); $data = (array) $data; if (!is_null($columnNames)) { $columnNames = (array) $columnNames; } $output = ''; foreach ($data as $key => $value) { if (isset($columnNames[$key])) { $output .= ''; } } }
public function create(Request $req) { if ($req->isMethod('post')) { $fields = []; foreach ($req->all() as $k => $v) { $fields[$k] = $v; } unset($fields['_token']); $p = new Post(); $p->create($fields); return view('post.post', ['posts' => Post::all()]); } return view('post.new'); }
/** * Assert that all posts shows correct pager * * @depends testAllPostsAreAccessibleBySlug * @return void */ public function testAllPostsShowsCorrectPager() { foreach (Post::all() as $post) { $this->visit('/posts/' . $post->slug); $this->seeStatusCode(200); $previous = Post::where('created_at', '<', $post->created_at)->max('created_at'); $next = Post::where('created_at', '>', $post->created_at)->min('created_at'); if (!is_null($previous)) { $this->see('Previous'); } if (!is_null($next)) { $this->see('Next'); } } }
public function posts() { $posts = Post::all(); foreach ($posts as $post) { Sitemap::addTag(route('post.show', $post), $post->updated_at, 'daily', '0.8'); Sitemap::addTag(route('post.showslug', $post->slug), $post->updated_at, 'daily', '0.9'); } $markers = Marker::all(); foreach ($markers as $marker) { Sitemap::addTag(route('post.showbymarker', $marker->id), $marker->updated_at, 'daily', '0.6'); Sitemap::addTag(route('post.showbymarkerslug', $marker->slug), $marker->updated_at, 'daily', '0.7'); } Storage::put('sitemap.xml', Sitemap::render()); copy(storage_path('app/sitemap.xml'), public_path('sitemap.xml')); return Sitemap::render(); }
/** * Show the application dashboard to the user. * * @return Response */ public function index() { $user = \Auth::user(); $posts = \App\Post::all(); $posts = \App\Post::paginate(3); $users = \App\User::all(); $users = \App\User::paginate(3); $fiches = \App\Fiche::all(); if ($user->role == "teacher") { $fiches = \App\Fiche::paginate(3); } if ($user->role == "teacher") { return view('back.index', compact('posts', 'users', 'fiches', 'user')); } else { return view('backStudent.index', compact('fiches', 'user')); } }
private function composeTotal() { view()->composer('partials.admin_sidebar', function ($view) { $view->with('totalusers', User::all()->count()); //total admin $view->with('totalparticipants', Participant::all()->count()); //total participant $view->with('totalevents', Event::all()->count()); //total event $view->with('totalposts', Post::all()->count()); //total post $view->with('totaltags', Tag::all()->count()); //total tag $view->with('totalimages', Image::all()->count()); //total image }); }
/** * Run the database seeds. * * @return void */ public function run() { /* Probably needs to be updated to NOT truncate User, so contributors pulling down and going through the ReadMe can first create a user, and then seed (allowing the seed to randomly generate posts, comments and subscriptions for the created user first) */ User::truncate(); Post::truncate(); Comment::truncate(); Subbreddit::truncate(); DB::table('subbreddit_user')->truncate(); $users = factory(User::class, 25)->create(); $users->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())); }); }