I recently started to build a large social network, and and I thought my structure was good but it turned out I built this logic up badly.

I mixed my views with AngularJS (bad idea), skipped blade extension, but since I'm using a lot of block and sidebar includes it became a pain in the butt.

Currently I am just handling form validations with angular, but actually all of my site pages will require ajax, data pulling, etc.

我在网上搜索时发现,Angular 视图存储在公共文件夹中,但是既然我所有的页面都将使用Angular 视图,那么将我所有的视图存储在公共位置,并且只使用Laravel作为后端是不是一个好主意?

我知道这是个愚蠢的问题,但我有点困惑.

Any help hint appreciated.

推荐答案

有两种方法可以组合这些框架:

  1. 仅客户端渲染

    这是大多数web应用程序使用的更简单的方法.在本例中,您将使用Laravel作为API端点,该端点将返回JSON.Angular可以通过其$http$resource服务查询这些数据,并编译存储在公用文件夹中的模板.Angular 模板只是带有指令和一些{var}}语句的HTML.这样也可以完成所有的布线.

  2. 服务器端和客户端呈现

    This is the harder way where Laravel would do the routing and compile some templates on the server-side. You would use Angular only for some interactions on the site in a way you would use jQuery for example. The benefit of this approach is performance as users will get the full HTML the first time they visit your site. The disadvantage is that you may have to write some logic twice and can’t use some of Angular’s features.

Laravel相关问答推荐

Laravel:在 PHPUnit 的覆盖率报告中包含文件夹(如果在 app/ 文件夹之外)?

在 laravel 5.3 中截断的错误日志(log)

如何访问 Validator::extend 中的其他输入属性?

Laravel 5.4 存储:下载文件.文件不存在,但显然存在

Laravel 没有定义

Laravel Artisan Scheduler 中的链式命令?

PHP 中的 Http 响应代码枚举

路由模型绑定不起作用

Laravel vagrant up 不工作 - Errno::EADDRNOTAVAIL

Laravel 5.4 - 注册后禁用自动登录

php Laravel-遇到格式不正确的数值(在字符串上)

在 AWS 上找不到 Laravel 5 类Collective\Html\HtmlServiceProvider

在 Laravel 中将 Eloquent 导出到 Excel 时如何包含列标题?

Laravel 中的单会话登录

Laravel League/flysystem 使用 AWS S3 获取文件 URL

Laravel 存储链接不适用于生产

Laravel Eloquent 模型属性

如何在 Laravel 测试中禁用选定的中间件

如何使用 Laravel 迁移在 Mysql 列中添加注释

Laravel 更新查询