本文整理汇总了PHP中app\Post::all方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::all方法的具体用法?PHP Post::all怎么用?PHP Post::all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Post
的用法示例。
在下文中一共展示了Post::all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct()
{
$this->postParser = new PostParser();
$this->tags = Tag::all();
$this->dificultyLevels = PostDificulty::all();
$this->posts = Post::all();
}
示例2: index
/**
* 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);
}
示例3: like
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);
}
示例4: index
public function index()
{
if (\Request::ajax()) {
return Post::all();
}
return view('post.index');
}
示例5: 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);
}
示例6: posts
public static function posts($type = null, $data = null)
{
if ($type and $data) {
return Post::where($type, $data)->get();
}
return Post::all();
}
示例7: index
/**
* 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);
}
示例8: handle
/**
* 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!');
}
示例9: run
/**
* 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)]);
}
}
示例10: index
public function index()
{
/**
* Loading all posts.
*/
$posts = Post::all();
return view('blog.list', compact('posts'));
}
示例11: store
/**
* 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'));
}
示例12: last
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();
}
示例13: index
/**
* 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);
}
}
示例14: posts
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' => '*']);
}
示例15: getContent
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"));
}