应用需要注意的点
1.select 和 with共用,select中必须包含关联表外键:store_id,with中必须指定关联表的主键:id
Goods::select(['id', 'store_id', 'name'])
->with(['store:id,name']);
2.勿使用两个单独的 ->with去预加载(导致无法预加载),多个关联可以数组的方式,写进 1个with中
3.框架软删除功能,在 join查询中,只会指定主表的软删除条件,影响外联表已软删的记录参与查询
4.框架软删除功能,查询条件用的是表全名,在指定主表别名的情况下,会提示字段找不到
可使用 setTable指定名称,但 setTable不可静态调用,故 (new UserModel())->setTable('xxx');
5.insert方法,需要自行维护 created_at 和 updated_at
6.自定义 created_at / updated_at格式化
use Illuminate\Support\Carbon;
public function getCreatedAtAttribute($value) {
return Carbon::parse($value)->format('Y-m-d H:i');
}
框架理解
中间件
Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode
Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull
Illuminate\Foundation\Http\Middleware\TransformsRequest
Illuminate\Foundation\Http\Middleware\TrimStrings
Illuminate\Foundation\Http\Middleware\ValidatePostSize
Illuminate\Foundation\Http\Middleware\VerifyCsrfToken
Illuminate\Auth\Middleware\AuthenticateWithBasicAuth
Illuminate\Auth\Middleware\Authorize
Illuminate\Auth\Middleware\RequirePassword
Illuminate\Auth\Middleware\EnsureEmailIsVerified
Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse
Illuminate\Http\Middleware\SetCacheHeaders
Illuminate\Routing\Middleware\SubstituteBindings:替代绑定,绑定路由参数到 model(显性/隐性)
Illuminate\Routing\Middleware\ValidateSignature
Illuminate\Routing\Middleware\ThrottleRequests
Illuminate\Session\Middleware\StartSession
Illuminate\Session\Middleware\AuthenticateSession
Illuminate\View\Middleware\ShareErrorsFromSession
App\Http\Middleware\Authenticate
App\Http\Middleware\CheckForMaintenanceMode
App\Http\Middleware\EncryptCookies
App\Http\Middleware\RedirectIfAuthenticated
App\Http\Middleware\ThrottleRequests
App\Http\Middleware\TrimStrings
App\Http\Middleware\TrustProxies
App\Http\Middleware\VerifyCsrfToken