쿼리 스코프(Query Scope)는 Laravel에서 데이터베이스 쿼리를 쉽게 작성하고 재사용할 수 있는 기능입니다. 주로 Eloquent 모델에서 정의되며, 특정 쿼리 조각이나 필터링 기준을 하나의 메서드로 묶어 사용할 수 있도록 도와줍니다.
쿼리 스코프를 사용하면 다음과 같은 이점이 있습니다:
1. **코드 재사용성**: 동일한 쿼리 조건이 여러 곳에서 필요할 때 매번 같은 쿼리를 반복해서 작성하는 것을 방지할 수 있습니다.
2. **가독성**: 코드를 읽고 이해하기 쉬워집니다. 독립적으로 정의된 쿼리 스코프는 모델을 사용하는 다른 부분과 분리됩니다.
3. **유지보수성**: 쿼리 스코프 내의 로직이 변경되면 모든 사용 사례에 자동으로 반영되므로 유지 보수가 용이합니다.
쿼리 스코프는 Laravel의 Eloquent 모델 클래스 내에서 `scope` 접두사로 정의됩니다. 예를 들어, 다음과 같이 정의할 수 있습니다:
```php class CodeValue extends Model { public function scopeCategoryKey($query, $categoryKey) { return $query->where('category_key', $categoryKey); } } ```
위의 예제에서 `scopeCategoryKey` 메서드는 `$query` 파라미터를 받아서 데이터베이스 쿼리 빌더 객체를 나타내며, 이를 통해 원하는 조건을 추가할 수 있습니다. 이후에는 모델에서 다음과 같이 사용할 수 있습니다:
restart 설정은 no, always, on-sucess, on-failure, on-abnormal, on-abort, on-watchdog가 존재하는데
각각 restart 기준은 아래 comman드 실행시 나오는 문서의 Restart= 부분에서 확인 가능하다
$ LANG=C man systemd.service
예를 들어 no로 설정할 경우 재실행은 이루어지지 않으며, always로 설정시 모든 경우에서 재실행이 된다고 보면 된다
그럼 현재 내 서버는 어떤 설정인지 확인해보자
$ less /usr/lib/systemd/system/apache2.service
Restart 설정이 되어있지만 on-abort로 설정되어있다
즉 Unclean signal일 경우만 자동으로 재실행해주는것이다
timeout을 재실행 해주는 설정은 always, on-failure, on-abnormal
그 중 나는 on-failure로 설정해주겠다
apache2.service에서 수정해도 되지만 업데이트 등 변경될 가능성이 있기때문에
systemctl edit으로 내용을 재정의해준다
$ sudo systemctl edit apache2
### Editing /etc/systemd/system/apache2.service.d/override.conf
### Anything between here and the comment below will become the new contents of the file
### Lines below this comment will be discarded
### /lib/systemd/system/apache2.service
# [Unit]
# Description=The Apache HTTP Server
# After=network.target remote-fs.target nss-lookup.target
# Documentation=https://httpd.apache.org/docs/2.4/
#
# [Service]
# Type=forking
# Environment=APACHE_STARTED_BY_SYSTEMD=true
# ExecStart=/usr/sbin/apachectl start
# ExecStop=/usr/sbin/apachectl graceful-stop
# ExecReload=/usr/sbin/apachectl graceful
# KillMode=mixed
# PrivateTmp=true
Restart=on-failure
#
# [Install]
# WantedBy=multi-user.target
<?php
namespace App\Http\Middleware;
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
class EncryptCookies extends Middleware
{
/**
* The names of the cookies that should not be encrypted.
*
* @var array<int, string>
*/
protected $except = [
'sidebar'
];
}