public function testIndex() { factory(\App\Models\Post::class, 5)->create(); $postsCount = \App\Models\Post::all()->count(); // index $this->logout()->request('GET', 'api/posts')->assertStatus(200)->assertKeyExists('result.data.0.id')->assertKeyChildrenCountEquals('result.data', $postsCount); // @TODO pagination? }
/** * Test samples for all models have been seeded. */ public function testModelSeed() { $message = 'Haven\'t you forgotten to run artisan migrate and db::seed?'; $this->assertNotEmpty(Author::all(), $message); $this->assertNotEmpty(Comment::all(), $message); $this->assertNotEmpty(Post::all(), $message); $this->assertNotEmpty(Site::all(), $message); }
public function run() { DB::table('comments')->delete(); $posts = Post::all()->lists('id')->toArray(); for ($i = 0; $i < 50; $i++) { Comment::create(['post_id' => $posts[array_rand($posts, 1)], 'name' => 'Annonim', 'comment' => 'My first post', 'published' => true]); } }
/** * Display a listing of the resource. * * @return Response */ public function index() { // $posts = Post::all(); $response = new \stdClass(); $response->success = true; $response->total = count($posts); $response->data = $posts; return response()->json($response); }
/** * Test samples for all models have been seeded. */ public function testModelSeed() { $message = 'Haven\'t you forgotten to run artisan migrate and db::seed?'; $this->assertNotEmpty(Author::all(), $message); $this->assertNotEmpty(Comment::all(), $message); $this->assertNotEmpty(Post::all(), $message); $this->assertNotEmpty(Site::all(), $message); $isAuthenticated = Auth::attempt(['email' => UsersTableSeeder::SAMPLE_LOGIN, 'password' => UsersTableSeeder::SAMPLE_PASSWORD]); $this->assertTrue($isAuthenticated); }
/** * Run the database seeds. * * @return void */ public function run() { $modelPost = new \App\Models\Post(); $posts = \App\Models\Post::all(['id']); foreach ($posts as $id) { for ($i = 0; $i < 10; $i++) { factory(\App\Models\Comment::class)->create(['post_id' => $id->id]); } } }
/** * Shows all posts. * * @return Response */ public function index() { // Get all the post models $posts = Post::all(); // Retrieve the user, or instantiate a new instance $user = User::firstOrCreate(['name' => 'Chris', 'email' => '*****@*****.**', 'password' => 'goteam123']); // Login with that user Auth::login($user); // Render the 'posts' view passing in the $posts as parameter 'posts' return View('posts')->with('posts', $posts); }
function galeria() { $posts = \App\Models\Post::all(); $tags = \App\Models\Tag::all(); $tagsUsados = []; $tagsTotal = []; $contTags = 0; $contTagsTotal = 0; foreach ($posts as $p) { foreach ($p->tags as $t) { $tagsUsados[$contTags] = $t->clave; $contTags++; } } foreach ($tags as $tag) { $tagsTotal[$contTagsTotal] = $tag->clave; $contTagsTotal++; } $tagsUsadosNeto = array_intersect($tagsTotal, $tagsUsados); return view('front.galeria')->with(array('posts' => $posts, 'tags' => $tags, 'tt' => $tagsUsadosNeto)); }
<?php Route::get('/', function () { // return view('allpost'); }); // ============== all posts/single posts ============== // Route::get('posts', function () { $posts = \App\Models\Post::all(); return view('allpost')->with("posts", $posts); }); Route::get('posts/{id}', function ($id) { $post = \App\Models\Post::find($id); return view('post', compact('post')); }); // ============== show user/create user ============== // Route::get('users/{id}', function ($id) { $user = \App\Models\User::find($id); return view('user', compact('user')); }); Route::post('users', function (\App\Http\Requests\CreateUserRequest $request) { $user = \App\Models\User::create($request->all()); $user->password = bcrypt('$user->password'); $user->save(); return redirect('users/' . $user->id); }); // ============== login/out/signup ============== // Route::get('users/create', function ($id) { return view('signup'); }); Route::get('login', function () { return view('login');
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $posts = \App\Models\Post::all(); return view('allPosts', ['post' => $posts]); }
} public static function _newestPublished($amount) { return static::_all('is_published = 1 order by created_on desc limit ' . (int) $amount); } public static function _query() { return array('tables' => array('posts', 'categories c'), 'fields' => array('c.*', 'posts.*'), 'conditions' => array('c.category_id = posts.category_id')); } } /**/ Post::event(array('_insert'), function ($self, $args, $chain) { if (isset($args->values['title']) && !isset($args->values['original_slug'])) { $slug = Output::slugify($args->values['title']); //var_dump($slug); $slugs = Post::all("original_slug LIKE ?", $slug . '%'); if ($slugs) { $nums = array(); $slugs = array_map(function ($post) use($slug, &$nums) { $nums[] = (int) substr($post->original_slug, strlen($slug) + 1); return $post->original_slug; }, $slugs); rsort($nums, SORT_NUMERIC); //print_r($slugs); //print_r($nums); $slug .= '-' . ($nums[0] + 1); //var_dump($slug); } //exit; $args->values['original_slug'] = $slug; }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $posts = \App\Models\Post::all(); $data = compact('posts'); return view('posts.posts', $data); }
public function index() { $postsPerPage = $this->_config('posts_on_index'); // Way 1 // Define which get method to use to fetch Posts by checking ACL // Use that function and the Model's logic to get those posts. $unpub = $this->user->hasAccess('blog read unpublished'); $method = $unpub ? 'newest' : 'newestPublished'; $posts = models\Post::$method($postsPerPage); // The quick 'n dirty // $page = Options::one($_GET, 'page', 1, false); $start = ($page - 1) * $postsPerPage; $conditions = $unpub ? '1' : 'is_published = 1'; $posts = models\Post::all($conditions . ' ORDER BY created_on DESC LIMIT ' . $start . ', ' . $postsPerPage . ''); // Don't do it! // // Way 2 // Define the difference in conditions here (instead of in the Model) $conditions = $unpub ? '' : array('is_published' => true); $numAllPosts = models\Post::count($conditions); // Way 3 // A third way would be a combination like this: /* $access = $this->user->hasAccess('blog read unpublished'); $posts = model\Post::postsByAccess($access, $this->_config('posts_on_index')); */ // That way you can check access in the Controller and have fetch logic in the Model $messages = Session::messages(); $canCreatePosts = $this->user->hasAccess('blog create posts'); return get_defined_vars(); // view will be rendered by row\Controller->_post_action return $this->_display(__METHOD__, get_defined_vars(), !$this->AJAX); // view will be rendered by Output->display return $this->_display(get_defined_vars()); // view will be rendered by Output->display }
/** * Display a listing of the resource. * * @return Response */ public function index() { $this->checkParametersEmpty(); return $this->getResponse(Post::all()); }
public function index() { $posts = Post::all(); return $this->response->array($posts); }
public function index() { $posts = Post::all(); $posts = Post::find('all', array('conditions' => 'created between 0 and 1000')); return compact('posts'); }
public function insert() { $allUser = User::all(); $params = ['body' => []]; for ($i = 0; $i < count($allUser); $i++) { SearchController::insertUser($allUser[$i]); } $allUser = Post::all(); $params = ['body' => []]; for ($i = 0; $i < count($allUser); $i++) { SearchController::insertPost($allUser[$i]); } $allUser = Board::all(); $params = ['body' => []]; for ($i = 0; $i < count($allUser); $i++) { SearchController::insertBoard($allUser[$i]); } }
public function getNumberFeeds() { return count(Post::all()); }
/** * Returns all Posts * * @return \Illuminate\Database\Eloquent\Collection|static[] */ public function all() { return Post::all(); }
/** * Index * * @param int $page * @return Response */ public function index($slug) { $posts = Post::all(); return view('home')->withPosts($posts); }
/** * Display a listing of the resource. * * @return Response */ public function index() { return $this->getResponse(Post::all()); }
public function posts() { $posts = \App\Models\Post::all(); return view('posts.posts', ['posts' => $posts]); }
/** * Display a listing of the resource. * * @return Response */ public function index() { // return view('admin.post.index')->withPosts(Post::all()); }
public function index() { $posts = Post::all(); return view('posts.index')->with('posts', $posts); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $posts = Post::all(); return view('frontend.post.index', compact('posts')); }
/** * Index * * @param int $page * @return Response */ public function index(Request $req, $page = null) { $result = Post::all(); return view('home', ['posts' => $result->posts, 'currentPage' => $result->currentPage, 'pageCount' => $result->pageCount]); }