I need a recommendation. I want to have a sidebar with all the titles of the posts and by clicking on any of them that this is loaded with its content in the main section of the page. The idea is that when loading the page not all the contents of each post are loaded, but only when clicking. What system can I use if I am using Laravel?
关注
码龄 粉丝数 原力等级 --
- 被采纳
- 被点赞
- 采纳率

已采纳
建议:如何使用laravel动态加载帖子[关闭]
收起
- 写回答
- 好问题 0 提建议
- 关注问题
微信扫一扫
点击复制链接分享
- 邀请回答
- 编辑 收藏 删除 结题
- 收藏 举报
1条回答 默认 最新
- 关注
码龄 粉丝数 原力等级 --
- 被采纳
- 被点赞
- 采纳率
duan_2000 2019-07-27 14:24关注You can return your post to the view using your controller:
public function someFunction() { $posts = Post::all(); return view('your-view', compact('posts')); }
Now, within your blade template, use the laravel
@foreach
blade directive to create your links to each post:Wihtin your view, where you want to display the links to the posts in your sidebar:
@foreach($post as $post) <a href="{{ route('posts.show', $post->id) }}> {{ $post->title }} </a> @endforeach
This code will create a link to each of the posts you have. In order to the
route('posts.show', $post->id)
work, you need to have a resource route for your post controller or define this route:Route::get('posts/{post}', 'YourPostController@show')->name('posts.show');
Then, just write your
show
method withing your post controller:public function show($id) { $post = Post::find($id); return view('your-view', compact('post'); }
Hope it helps.
本回答被题主选为最佳回答 , 对您是否有帮助呢? 本回答被专家选为最佳回答 , 对您是否有帮助呢? 本回答被题主和专家选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏举报微信扫一扫
点击复制链接分享
编辑预览轻敲空格完成输入- 显示为
- 卡片
- 标题
- 链接
评论按下Enter换行,Ctrl+Enter发表内容
编辑
预览

轻敲空格完成输入
- 显示为
- 卡片
- 标题
- 链接
报告相同问题?
提交
- 2018-06-11 21:00回答 3 已采纳 As you are calling function sendemail() from route. It's passing only one parameter to it like: s
- 2014-11-28 00:18回答 2 已采纳 I fixed it using the below code. I do not know if this code is efficient but it fixed my issue. p
- 2018-10-18 10:52回答 1 已采纳 I suspect when you called mapWithKeys you did not return a Model instance. That's what's causing t
- 2021-03-26 05:54weixin_39587029的博客 使用laravel做后台数据统计的时候,需要查询每天的注册量之类的数据这时候如果直接用created_at分组,是不好用的。1、所以本文解决这个查询应该怎么写。2、并且推荐一个时间选择插件,因为统计中一定会用到,本周...
- 2019-08-05 00:21回答 2 已采纳 As I understand it, the problem is that after the first POST, you land on a new page where validat
- 2015-09-07 08:54回答 6 已采纳 You have to perform chmod recursively to make sure all subdirectories also carry the same permissi
- 2014-05-02 23:23回答 1 已采纳 This is the same question as "which fruit is better?" :-) If you are looking for a well tested fr
- 2020-08-02 23:41cumt951045的博客 qgis在地图上画导航线For further process we need to know something about it, ...The route is a core part in Laravel because it maps the controller for sending a request which is automati...
- 2016-05-14 02:46回答 1 已采纳 Basically, findOrFail() finds a single result for you instead of returning a collection. What that
- 2016-11-14 06:48回答 2 已采纳 You can add your namespace to the autoloader like this : $loader = require 'vendor/autoload.php'
- 2017-04-20 00:52回答 1 已采纳 I had a similar issue, and enabling NFS for folder sharing fixed it. Add NFS to ~/Homestead/Homest
- 2020-08-15 15:10culh2177的博客 如果您使用的是其他Vagrant框,而xdebug不存在,请参阅Shameer的帖子以获取安装说明。 配置xdebug.ini (Configuring xdebug.ini) To allow Xdebug to be used remotely, we need to alter the ini file and give it...
- 2023-04-24 04:15青木客的博客 php的面试集结(会持续更新)
- 2018-01-28 07:28jianghu0的博客 普通索引:使用字段关键字建立的索引,主要是提高查询速度 唯一索引:字段数据是唯一的,数据内容里面能否为 null,在一张表里面,是可以添加多个唯一索引。 全文索引:在比较老的版本中,只有 myisam引擎支持...
- 2021-04-18 06:52西橙柠的博客 单例和原型模式-创建型单例模式确保一个特殊类的实例是独一无二的(它是这个类的唯一实例),并且这个实例易于被访问。解决方案1)全局变量:一个全局变量...文章jephon2016-08-25450浏览量PHP面向对象(OOP)编程入门...
- 没有解决我的问题, 去提问
联系我们(工作时间:8:30-22:00)
400-660-0108kefu@csdn.net在线客服
- 京ICP备19004658号
- 经营性网站备案信息
公安备案号11010502030143
- 营业执照
- 北京互联网违法和不良信息举报中心
- 家长监护
- 中国互联网举报中心
- 网络110报警服务
- Chrome商店下载
- 账号管理规范
- 版权与免责声明
- 版权申诉
- 出版物许可证
- ©1999-2025北京创新乐知网络技术有限公司