laravel

Laravel Timestamp Being Updated Without Explicit Call To Do So

大憨熊 提交于 2021-02-04 07:31:45
问题 So I'm running into an annoying problem with Laravel update and save. I have a model/table Invoice and invoices , that has a timestamp sent_at . Invoice.php class Invoice extends Model { protected $dates = [ "sent_at", ]; } I have the following function that updates the Invoice : InvoicesController.php : public function postPayInvoice(Request $request, $invoiceId){ $user = $this->apiResponse->user; $invoiceItemIds = $request->input("invoice_item_ids"); $invoice = Invoice::with(["invoiceItems"

laravel created_at updated_at deleted_at 种种

与世无争的帅哥 提交于 2021-02-03 11:40:24
----题记,写东西排版很丑;假期复习下md,到时拿本篇开涮 1. 默认laravel的model如果使用了 SoftDeletes Trait 则 会对表的delete 方法使用软删除; 1.1 如果仍要硬删,则使用 forceDelete 方法; 1.2 如果查询时候不需要带入deleted_at条件,则需要调用 withTrashed 方法,建议无删除逻辑的select都加上,数据量多的时候,where默认带的deleted_at还是需要优化的 1.3 如果表不带有deleted_at ,Model 层则可以不再使用 SoftDeletes Trait;此时delete 使用的硬删 1.4 如果你基类强制使用了 SoftDeletes Trait; 1.4.1 你某张表想给deleted_at换个名字,则在该model中定义 const DELETED_AT = null ; //使用软删的表中deleted_at字段名 1.4.2 你某张表不想使用、定义deleted_at , 即废弃基类的软删限制;则可以如下: public static function bootSoftDeletes () {} //覆盖trait 的软删逻辑 2. 相应的 created_at 和 updated_at 如果换名的话,可以指定model的 const CREATED_AT =

Laravel注意事项

为君一笑 提交于 2021-02-02 11:03:41
一、脚本 1、重新加载 composer dump-autoload 2、检查语法 php -l database/seeds/MarketingService1127.php 3、执行脚本 nohup php artisan db:seed --class=MarketingService1127 二、打日志 SQL日志 app.php 三、修改线上配置文件.env后,要用php artisan config:clear 命令 清楚配置缓存 四、laravel的redis的key会默认在最前面加一个“laravel:”,而且打印不出来 五、清楚route缓存:php artisan route:cache(新加路由要用) 六、注册route缓存:php artisan api:cache 来源: oschina 链接: https://my.oschina.net/u/3670641/blog/1802457

Beginner in Laravel Delete data using modal

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-02 10:00:38
问题 My modal works so well and can delete data but not the exact id that i selected to delete like example id: 1, 2, 3, 4 and i will select id: 4 but the id: 4 will not delete the id deleted is id: 1 this is my delete function inside AllSystemController public function deletestorydata($id) { $story = Story::findOrFail($id); $story->delete(); return redirect()->back()->with('success', 'Data has successfully deleted.'); } and this is my route web.php in story section Route::get('stories/table',

Beginner in Laravel Delete data using modal

我的未来我决定 提交于 2021-02-02 10:00:01
问题 My modal works so well and can delete data but not the exact id that i selected to delete like example id: 1, 2, 3, 4 and i will select id: 4 but the id: 4 will not delete the id deleted is id: 1 this is my delete function inside AllSystemController public function deletestorydata($id) { $story = Story::findOrFail($id); $story->delete(); return redirect()->back()->with('success', 'Data has successfully deleted.'); } and this is my route web.php in story section Route::get('stories/table',

Beginner in Laravel Delete data using modal

你说的曾经没有我的故事 提交于 2021-02-02 09:58:28
问题 My modal works so well and can delete data but not the exact id that i selected to delete like example id: 1, 2, 3, 4 and i will select id: 4 but the id: 4 will not delete the id deleted is id: 1 this is my delete function inside AllSystemController public function deletestorydata($id) { $story = Story::findOrFail($id); $story->delete(); return redirect()->back()->with('success', 'Data has successfully deleted.'); } and this is my route web.php in story section Route::get('stories/table',

Laravel Vue You may need an appropriate loader to handle this file type,

人走茶凉 提交于 2021-02-02 08:47:25
问题 fresh Laravel installation on compiling files using npm run dev VUE file error "You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file" Laravel Verion : "^8.12" Package.json "devDependencies": { "axios": "^0.21", "laravel-mix": "^6.0.6", "lodash": "^4.17.19", "vue": "^2.5.17", "vue-loader": "^15.9.6", "vue-template-compiler": "^2.6.10" } blade file <div id="app"> <hello></hello> </div> <script src="{{mix('js/app.js')}}"></script>

用PHP做一个领取优惠券的活动

南楼画角 提交于 2021-02-01 11:11:18
业务需求 优惠券活动,具体还是要根据自己的需求。以下是最近实现的优惠券活动,主要的业务需求:根据后端设置优惠券模板,用户类型设置,优惠券活动的开始与结束时间,最后生成不同的优惠券活动链接。 代码环境: 源码主要laravel5.8,一整个活动要贴的代码很多,下面主要贴核心代码,仅供参考。主要还是要根据自己的业务需求来实现功能吧。 以下是后端截图,做成模块化 前端需要做的设置与限制: 1 判断优惠券是否存在或者停用 2 判断活动开始时间与优惠券开始时间 接着领取活动优惠券,需要判断以下情况: 1 活动已结束 2 活动为开始时 3 活动为新用户领取,而领取的用户是老用户 4 活动为老用户领取,而领取的用户是新用户 5 优惠券是否领取完 6 已领取过优惠券提示 7 领取成功 下面核心代码实现 /** * Function:优惠券领取处理 * Author:cyw0413 * @param $params * @return array * @throws \Exception */ public function doCoupon ( $params ) { $activity_id = $params [ 'activity_id' ]; if ( ! $params ){ throw new \Exception ( "参数错误!" ); } $preg_phone = '/^1

怎么理解Laravel的核心架构

不羁的心 提交于 2021-02-01 05:37:32
使用过larave框架的朋友都知道laravel框架里面除了提供一些基本的功能(如控制器、视图、模型)之外,还有中间件、门面、契约等,这些东西是如何在laravel框架运用起来的呢?今天就和大家详聊一下。 首先应该了解laravel框架的架构模式(设计核心,laravel 框架是使用服务组件化的开发模式开发的,laravel框架就是由不同的服务组件构成的) laravel 里面多个服务提供者构成了laravel组件。分层设计:把相同功能的类库放在同一个文件夹里面。 laravel框架有多个类组成服务,由多个服务组成组件。类 -> 服务 -> 组件 laravel使用组件化的开发模式,多个类 -> 服务 -> 组件,多个类组成服务,多个服务构成组件。 多个组件提供不同的服务,然后多个服务构成我们的项目。 请求生命周期 大概的流程如图: 理论上,生命周期主要有这么些阶段,但其中,开发者大多数只需关注 路由、中间件、控制器、闭包函数、逻辑处理 等几步 当然,每一步的内部,还是会有更多细化的执行流程,在这里,一般不深入研究框架或改造框架,很少会细化研究,但研究底层,依旧是学习的好选择。 服务 说的就是提供给你所需要的东西,在laravel里面所提供的服务有 认证服务、数据库服务、缓存服务、队列服务等等。laravel框架所有服务都定义在了 app/config/app.php 里面

微信小程序通过getPhoneNumber后台PHP解密获取用户手机号码

╄→гoц情女王★ 提交于 2021-01-31 05:32:57
之前做的版本用户这块是以获取用户openid为凭证,最近改版重新整理了一下,新增注册登录以手机号码为主, 两种(正常注册手机号码-密码+一键获取当前用户手机号码) getPhoneNumber这个组件要通过button来实现。将button中的open-type=“getPhoneNumber”,并且绑定bindgetphonenumber事件获取回调。 在使用这个组件之前必须先调用 login 接口 然后传递code,iv,encryptedData参数到后台,后台解密 示例 <button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber" hover-class="none">一键自动注册</button>    getPhoneNumber: function (e) { console.log(e.detail.errMsg) if (e.detail.errMsg == 'getPhoneNumber:fail user deny') { wx.showModal({ title: '提示', showCancel: false, content: '未授权', success: function (res) { } }) } else { wx.login({ success: function