Laravel Eloquent? ?? ?? ??? ???? ?? ??? ???? ???? ??? ???? ? ????. ?? ?? ??? ??? ??? ???? ??? ? ??? ???? ???? ?? ?????. ?? ??? ???? ??? ???? ???? ?? ???? ??? ? ????.
1. ?? ??
??:
?? ??? ?? ??? ?????. ? ??? ??? ??? ? ???? ????? ?? ??? ??? ????. ?? ??? ??, ?? ?? ?? ???? ? ?????.
?? ?? ???:
1. ?? ?? ??? ???:
Laravel?? Global Scope? ???? ???? Scope
?????? ??? ???? ?????.
use Illuminate\Database\Eloquent\Scope; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Builder; class ActiveScope implements Scope { public function apply(Builder $builder, Model $model) { $builder->where('active', 1); // ?????? ??????? } }
2. ??? ?? ?? ??:
??? booted()
???? ???? ???.
use App\Models\Post; use App\Scopes\ActiveScope; class Post extends Model { protected static function booted() { static::addGlobalScope(new ActiveScope); } }
?? Post::all()
? ???? active = 1
??? ???? ?????.
3. ?? ??? ????? ??:
use Illuminate\Database\Eloquent\Scope; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Builder; class ActiveScope implements Scope { public function apply(Builder $builder, Model $model) { $builder->where('active', 1); // ?????? ??????? } }
??? ?? ?? ??? ????? ???? active
??? ??? ?? ???? ?????.
2. ?? ??
??:
?? ??? ?? ??? ?? ?? ?? ??? ?? ????? ??? ?? ?????. ?? ???? ?? ???? ???? ????? ????.
?? ?? ???:
? ?? ?? Builder
? ???? ??? ?? ???? ???? ?? ??? ????.
use App\Models\Post; use App\Scopes\ActiveScope; class Post extends Model { protected static function booted() { static::addGlobalScope(new ActiveScope); } }
?? ?? ??:
$posts = Post::withoutGlobalScope(ActiveScope::class)->get();
?? ??? ???? ??:
????? ?? ??? ??? ? ????.
use App\Models\Post; class Post extends Model { // ????? ????? public function scopeActive($query) { return $query->where('active', 1); } public function scopeDraft($query) { return $query->where('status', 'draft'); } }
?? status
????? ?? ??? ??? ? ????.
// ?????? ????? ????: $posts = Post::active()->get(); // ?????? ????? ????: $draftPosts = Post::draft()->get(); // ???? ??? ???????: $activeDraftPosts = Post::active()->draft()->get();
'???'? ???????.
3. ?? ??
?? ??? ?? ??? ???? ??? ? ?? ?? ??? ? ?????. Laravel??? scopeName()
?? ??
class Post extends Model { // ????? ????? public function scopeStatus($query, $status) { return $query->where('status', $status); } }
?? ??? ???? ??? ? ????.
$posts = Post::status('published')->get();
?? scopePublished()
??? ???? ?????.
4. ?? ??
?? ??? ??? ? ????. ?? ?? status
? active
??? ?? ??? ? ????.
use Illuminate\Database\Eloquent\Scope; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Builder; class ActiveScope implements Scope { public function apply(Builder $builder, Model $model) { $builder->where('active', 1); // ?????? ??????? } }
active
, status('published')
?? ?????.
5. ?? ??? ??
Eloquent? ?? ???? ?? ????? ?? ???? ??? ??? ? ????.
use App\Models\Post; use App\Scopes\ActiveScope; class Post extends Model { protected static function booted() { static::addGlobalScope(new ActiveScope); } }
???? 3? ?? orderBy
1?? ???? ????.
? ??? ???? ?? ?? ??? Laravel Eloquent ORM)? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

TOSECIBERYNECTTOEREMOTEMYSQLSERVER, USESSHTUNNENG, CONFIGUREMYSQLFORREMOTEACCESS, SETFIREWALLRULES ? CONSIDERSSLENCRYPTION .First, SpectionANSSHTUNNELWITHSSH-L3307 : LocalHost : 3306user@remote-Server-NandConnectViamySQL-H127.0.1-P3307.second, editmys

MySQL ??? ?? ??? ?? ?? ??? ?? ??? ??????. 1. ?? ?? ?? ?? ???? Slow_Query_Log ? Long_Query_Time; 2. ???? ??? ?? ??? ???? ? ????? query_time, lock_time, rows_examined? ?? ?? ??? ???? ????. 3. ??? ????? ???? ?? mysqldumpslow ?? pt-query idigest ??? ??????. 4. ??? ???? ??? ??, ??*???*, ??? ?? ?? ?? ?????. ?? ??, user_id? ???? ???? ?? ? ?? ?? ?? ??? ?? ???? ???? ? ????.

MySQLDump? MySQL ??????? ??? ??? ???? ???? ?????. ??????? ???? ?? ?? ? ?? ?? ???? SQL ??? ?????. 1. ?? ??? ????? ??? ?????? ??? ???? ??? SQL ???? ?????. 2. ??? ?????? ?? ??? ??? ???? TB ?? ???? ?? ???? ???? ????. 3. ???? ???-single transaction,-databases,-all-databases,-routines ?; 4. MySQL ??? ???? ?? ?? ?? ?? ?? ? ??? ?? ??? ???? ? ????. 5. ??? ????? ????? ?? ? ?? ??? ???? ?? ????.

MySQL?? NULL ?? ?? ? ? 1. ???? ?? ? ? ? ??? NotNull? ???? ?? ??? NULL? ?????. 2. iSnull ?? ISNOTNULL = ??! =; 3. Ifnull ?? Coalesce ??? ????? ???? ???? ? ??? ? ????. 4. ?? ?? ????? NULL ?? ?? ??? ?? ???? ??? ?? ? ORM ??? ?? ?? ?????? ??????. NULL? ???? ?? ?? ???? ??? ???? ?? ?? ?? ????. ??? ???? ??, ?? ? ???? ?? ? ??? ?? ??? ??? ?? ???????. ??? ??? ???? ??? ?? ?? ??? ????? ?? ? ????.

MySQL ?????? ? ???? ??? ??? information_schema? ?? ????? ?? ? ??? ??? ? ????. 1. ?? ?????? ?? ?? : SQL ?? ???? selecttable_schemaas'database ', sum (data_length index_length)/1024/1024as'size (mb) 'frominformation_schema.tablessgroupbytable_schema; ?? ??????? ? ??? ??? ?? ??????? ???? ??? ?? ? ? ????. 2. ?? ??? ??? ?????? : selectta? ??????

?? ?? ? ?? ?? ??? ??? ??? ?????? ?? ??? ??? ?????? ??? ?????? ?????? ??? ?????. ? ?? ?? ???? ????. ??, ??????, ??? ? ??? ?? ??? UTF8MB4? ???? ???? ShowCreatedAtabase/Table? ???? ? Alter ??? ??????. ??, ?????? ??? ? UTF8MB4 ?? ??? ???? ?? ?? ??? ????? SetNames? ??????. ??, ?? ??? ????? ???? UTF8MB4_UNICODE_CI? ???? ?? ? ????? ???? ???? ?????? ???? ?? ? ? ?? ?? ??? ????? ??????.

GroupBy? ???? ???? ????? ?? ??? ???? ? ???? ??? ? ??? ????? ? ?????. ?? ??, GroupByCustomer_ID? ???? ? ??? ? ???? ??? ? ????. ???? ? 1,000 ? ??? ? ??? ??? ?? ? ? ????. ?? ? ? ?? ??? GroupBy? ??????, ?? ?? ?? ???? ???? ??? ??? ? ? ????. ???? ???? ? ??? ? ??, ?? ?? ??? ? ?? ???? ???? ?????.

MySQL? ???? ??? ???? InnoDB ?? ??? ???? ??? ???? ???? ?????. 1. ????? ??? SQL ?? ????, ?? ?? ?? ?? ??? ?????. 2. ? ???? ???, ???, ?? ? ???? ?????. 3. ????? ???? ????? ??? STARTTRANSACTION, CONMING ? ROLLBACK???. 4. 4 ?? ?? ???? ?? ??, ?? ? ??, ?? ??? ?? ? ???? ?????. 5. ????? ???? ???? ?? ??? ??? ?? ??? ?? ?? ? ??? ????? ??????. ??? ????? ?? MySQL? ?? ???? ?? ??? ?? ? ? ????.
