laravel/framework v11.3.0
https://github.com/laravel/framework/releases/tag/v11.3.0
以下は、Laravelのリリースノートの要約です:
- Laravel 10.xでは、キューワーカーにおけるRedis接続エラーの報告の洪水を防ぐ改善が行われました。
- Laravel 11.xでは、エラーレスポンスがキャッシュされないようにSetCacheHeadersを最適化し、セッションに`hasAny`メソッドを追加しました。
- ThrottlesExceptionsミドルウェアでスロットルされた例外を報告するオプションが追加され、DeleteWhenMissingModels属性が導入されました。
- TrimStringsの`$except`をカスタマイズできるようになり、Contextにpullメソッドが追加されました。
- MariaDbGrammarから冗長なコードが削除され、PHP 8.4の非推奨に対応するために明示的なnullableパラメータ宣言が追加されました。
- キャッシュストアにセッターが追加され、Laravel 10.xではhasTableに`withSize`オプションがオプショナルで追加されました。
- artisanコマンドで欠けている配列引数のプロンプトが修正され、Eloquentにstrict-mode安全な`hasAttribute`メソッドが追加されました。
- `retry`関数がExceptionの代わりに"Throwable"をキャッチするようになり、NotificationFakeに`serializeAndRestore()`が追加されました。
- HttpClientのリトライロジックでConnectionExceptionを処理する際のクラッシュを防ぐ改善が行われました。
- 不明なパラメータの削除、PHPDocのタイポ修正、dockblockの修正が行われました。
- データベースロックで時間を偽装できるようになり、`Http::createPendingRequest()`メソッドが導入されました。
- いくつかのdoc blocksに`@throws`が追加され、PHP_MAXPATHLENのチェックがビューのファイル存在チェックに対して修正されました。
- BelongsToMany関係からスコープを削除できるようになり、名前付きレートリミッターとモデルプロパティが存在しない場合に例外を投げるようになりました。
これらの変更は、Laravelの機能強化、バグ修正、および最適化を目的としています。
#laravel
laravel/framework v10.48.5
https://github.com/laravel/framework/releases/tag/v10.48.5
以下は、Laravelのリリースノートの要約です:
1. **Redis接続エラー報告の洪水をキューワーカーで防ぐ**:
- Laravel 10.xにおいて、キューワーカーでRedis接続エラーが大量に報告される問題を防ぐ改善が行われました。この変更は@kasusによって提案され、プルリクエスト#50812で実装されました。
2. **Laravel 10.xでの`hasTable`に`withSize`オプションの追加**:
- Laravel 10.xでは、`hasTable`メソッドに`withSize`オプションを指定できるようになりました。これにより、テーブルが存在するかどうかをチェックする際に、テーブルのサイズもオプションで取得できるようになります。この機能は@apspanによって提案され、プルリクエスト#50888で追加されました。
3. **`NotificationFake`に`serializeAndRestore()`を追加**:
- Laravel 10.xにおいて、テスト用の`NotificationFake`クラスに`serializeAndRestore()`メソッドが追加されました。これにより、通知のシリアライズと復元が容易になり、テストの柔軟性が向上します。この変更は@dbpolitoによって提案され、プルリクエスト#50935で実装されました。
これらの変更は、Laravel 10.xの機能強化とテストの改善に貢献しています。
#laravel
### Laravelに関するよくある質問と回答
#### Q: Laravelで環境変数を設定するにはどうすればよいですか?
#### A: Laravelで環境変数を設定するにあたっては、プロジェクトのルートにある`.env`ファイルを編集します。このファイルでは、データベース接続情報やメールサービスの設定など、アプリケーションが実行される環境ごとに異なる可能性がある設定値を指定できます。例えば、データベースの接続情報を設定するには、次のように`.env`ファイルを編集します。
```plaintext
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
```
この操作により、アプリケーションはこれらの環境変数を利用して、指定されたデータベースに接続します。その他の環境依存の設定も同様に`.env`ファイルで行うことが推奨されます。環境変数の値は、Laravelの`config`ファイル内で`env`関数を用いて取得することができます。例として、データベースの設定ファイルである`config/database.php`内でこれを利用する場面があるでしょう。
重要なこととして、`.env`ファイルはアプリケーションのセキュリティに直結する情報を含むため、バージョン管理システムには追加しないようにしてください(Laravelでは標準で`.gitignore`に含まれています)。各開発者や本番環境では、環境に応じた設定が`.env`ファイルを通じて行われるべきです。
#laravel
livewire/livewire v3.4.10
https://github.com/livewire/livewire/releases/tag/v3.4.10
このリリースノートの要約は以下の通りです。
### 変更点
- `forms.md`と`actions.md`の更新、`wire:navigate`のバックボタン問題の修正、空の入力を扱うためのfloat synthesizerの追加など、Livewireのドキュメントと機能に多くの改善が加えられました。
- コマンドの遅延実行化、Alpine.jsの複数インスタンスに関する警告の追加、トラブルシューティングのドキュメントページの追加など、開発者の利便性を向上させる変更が行われました。
- Laravel 11のテストの再有効化、ファイル入力のクリア問題の修正、ナビゲート時のハッシュタグやクラスバインディングのブラウザテストの追加など、テストと互換性に関する改善が施されました。
- イベントリスナーのリーク防止、クエリパラメータの扱い、Enum属性の扱いなど、細かなバグ修正が多数行われました。
### 新規コントリビューター
- @danie-ramdhani, @lsmedia, @robert-stanciu, @buismaarten, @n1crack, @AlexandreBonaventure, @TobMoeller が初めての貢献を行いました。
このリリースでは、Livewireの機能強化、ドキュメントの改善、バグ修正、そして新規コントリビューターの参加が見られます。
#laravel
laravel/jetstream v5.0.2
https://github.com/laravel/jetstream/releases/tag/v5.0.2
チームサポートを使用してインストールする際に、@miclausによって https://github.com/laravel/jetstream/pull/1461 でDatabaseSeederをコピーするようになりました。
#laravel
laravel/breeze v2.0.2
https://github.com/laravel/breeze/releases/tag/v2.0.2
Laravel Breezeのバージョン2.xにおいて、@nunomaduroによるhttps://github.com/laravel/breeze/pull/377のプルリクエストで「(experimental)」ラベルが削除されました。
#laravel
laravel/laravel v11.0.5
https://github.com/laravel/laravel/releases/tag/v11.0.5
Laravelの次のリリース(11.x)では、@philbates35によってPHPUnitのバージョン11が使用されるようになります。詳細は https://github.com/laravel/laravel/pull/6385 で確認できます。
#laravel
laravel/framework v11.2.0
https://github.com/laravel/framework/releases/tag/v11.2.0
Laravelの最新リリースノートの要約は以下の通りです。
- ドキュメントブロック内の`@param`と`@return`タグを更新しました。
- 古いPostgreSQLで生成されたカラムの取得に関する問題を修正しました。
- 不可視文字をトリムする機能を追加しました。
- `Context`の`get`と`getHidden`にデフォルト値を設定しました。
- `serve` Artisanコマンドを改善しました。
- ユーザーがログインする際に一度だけパスワードを再ハッシュするようにしました。
- 存在しないデータベースを削除しようとした際に、データベースを消去しないようにしました。
- データベース作成失敗時の処理を改善しました。
- SQL Serverでデフォルトのスキーマ名を使用するようにしました。
- `startedAs`と`virtualAs`データベースカラム定義の型指定を修正しました。
- Many-to-Many関係でカラムとしてクエリExpressionを渡せるようにしました。
- `Middleware::trustHosts(subdomains: true)`の問題を修正しました。
- `getGateArguments`と`resolve`メソッドのドキュメントブロックを修正しました。
- 文字列のトリムメソッドを追加しました。
- フルエントヘルパーとコンテキスト用の新しいヘルパーを追加しました。
- ジョブインスタンスに`assertChain`と`assertNoChain`を追加しました。
- いくつかのクラスで冗長な`getDefaultNamespace`メソッドを削除しました。
- MariaDbConnectorでのConnectorInterfaceの冗長な実装を削除しました。
- `orderByRaw`を使用した後に`cursorPaginate`を使用する際のエラーを修正しました。
これらの変更は、主にLaravelフレームワークの品質向上、機能強化、およびユーザビリティの改善に貢献しています。
#laravel
### Laravelのよくある質問とその回答
**Q: Laravelでマイグレーションを作成する方法は?**
**A:** Laravelでマイグレーションを作成するには、ターミナルまたはコマンドプロンプトを開き、Laravelプロジェクトのルートディレクトリに移動して以下のコマンドを実行します。
```bash
php artisan make:migration create_テーブル名_table
```
上記のコマンドでは`テーブル名`を作成したいテーブルの名前に置き換えてください。例えば、ユーザーテーブルを作成する場合は以下のようになります。
```bash
php artisan make:migration create_users_table
```
このコマンドを実行すると、`database/migrations`ディレクトリに新しいマイグレーションファイルが作成され、そのファイル内でテーブルの構造を定義できます。
#laravel
laravel/framework v11.1.1
https://github.com/laravel/framework/releases/tag/v11.1.1
Laravelの最新リリースノートの要約は以下の通りです。
- ドキュメントブロック内の`@param`を更新する修正が行われました(https://github.com/laravel/framework/pull/50791)。
- クエリビルダーの`whereBetween`がCarbonPeriodとCarbon 3で機能するように修正されました(https://github.com/laravel/framework/pull/50792)。
- Artisanコマンドで出力がないことをアサートする機能が追加されました(https://github.com/laravel/framework/pull/50702)。
- タイポの修正が行われました(https://github.com/laravel/framework/pull/50808)。
- `DB::usingConnection()`が読み書きのタイプを尊重するように修正されました(https://github.com/laravel/framework/pull/50806)。
- Carbon 3.2によって引き起こされる非推奨警告の修正が行われました(https://github.com/laravel/framework/pull/50813)。
#laravel
tailwindlabs/tailwindcss v3.4.3
https://github.com/tailwindlabs/tailwindcss/releases/tag/v3.4.3
次のリリースノートの要約は以下の通りです:
- グロブ処理に関する変更を元に戻しました。 ([#13384](https://github.com/tailwindlabs/tailwindcss/pull/13384))
#laravel
tailwindlabs/tailwindcss v3.4.2
https://github.com/tailwindlabs/tailwindcss/releases/tag/v3.4.2
このリリースノートでは、Tailwind CSSのいくつかの修正と改善が行われています。主な内容は以下の通りです。
- ボタンと入力のPreflightルールに対して、最大の特異性`0,0,1`を保証する修正が行われました。
- ファイルパスに`(`, `)`, `[`, `]`が含まれるフォルダのglob処理が改善されました。
- `experimental.optimizeUniversalDefaults`を使用する際に、`:has`ルールを分割するようになりました。
- 複数のクラスリストにわたって任意のプロパティをアルファベット順に並べ替えるようになりました。
- `mix-blend-plus-darker`ユーティリティが追加されました。
- バリアント修飾子内でダッシュが許可されるようになりました。
- カスタムセパレータを使用している際にIntellisenseで補完を表示する際のクラッシュを修正しました。
- 設定ファイル内の`import.meta.url`をトランスパイルするようになりました。
- フォーム要素の文字間隔をリセットする修正が行われました。
- `xx-large`が欠けていた問題を修正し、`x-large`の重複を削除しました。
- ネストされたCSSに遭遇した際に、ネスティングを使用するクラスを`@apply`しようとしている場合以外はエラーにならないようになりました。
- 任意のプロパティが`important`設定を尊重するようになりました。
- ダークモードセレクタが変更され、擬似要素と正しく動作するように`@apply`が修正されました。
これらの修正と改善により、Tailwind CSSの使い勝手が向上しています。
#laravel
laravel/jetstream v5.0.1
https://github.com/laravel/jetstream/releases/tag/v5.0.1
Laravelの5.xバージョンにおいて、@timacdonaldによって提案された変更が https://github.com/laravel/jetstream/pull/1455 で実装されました。この変更により、コマンドが「lazy」になります。つまり、コマンドが実際に必要とされるまでロードや実行が遅延されるようになり、アプリケーションのパフォーマンスが向上します。
#laravel
laravel/breeze v2.0.1
https://github.com/laravel/breeze/releases/tag/v2.0.1
このリリースノートの要約は以下の通りです:
- @edikurniawan-devによって、重複する"id"属性を削除する変更が行われました。
- @mpociotによって、Laravel BreezeにLaravel Herdが追加されました。
- @timacdonaldによって、コマンドが遅延実行されるように変更されました(バージョン2.x向け)。
- @nunomaduroによって、Livewireの`welcome/navigation.blade.php`でダークモードが適用されない問題が修正されました(バージョン2.x向け)。
#laravel
laravel/laravel v11.0.4
https://github.com/laravel/laravel/releases/tag/v11.0.4
Laravelの次のリリースノートの要約は以下の通りです。
- `env`ヘルパーから不要なnullパラメータが削除されました。これは`cache.php`と`queue.php`の両方に適用され、@siarheipashkevichによって行われました(https://github.com/laravel/laravel/pull/6374、https://github.com/laravel/laravel/pull/6373)。
- `retry_after`が整数であるように修正されました。この修正は@driesvintsによって行われました(https://github.com/laravel/laravel/pull/6377)。
- ホバーアニメーションとリングに関する修正が行われました。この修正は@michaelnabil230によって行われました(https://github.com/laravel/laravel/pull/6376)。
#laravel
laravel/framework v11.1.0
https://github.com/laravel/framework/releases/tag/v11.1.0
Laravelの11.xリリースノートの要約は以下の通りです。
- MySQLのトランザクション分離レベルの修正が行われました。
- SESメールトランスポートにListManagementOptionsが追加されました。
- データベースクエリで非バックエンドのenumを受け入れるようになりました。
- `Context`に`Conditionable`トレイトが追加されました。
- `Context`のドキュメントブロックに`@throws`セクションが追加されました。
- nullableなカラムの変更をテストする機能が追加されました。
- HASH_VERIFY環境変数が導入されました。
- Unixタイムスタンプをキャストする際にデフォルトのタイムゾーンが適用されるようになりました。
- `ApplicationBuilder::withCommandRouting()`の使用法に関する修正が行われました。
- アプリケーションが起動した後にコンソールコマンド、パス、ルートが登録されるようになりました。
- 不正なリクエストの処理が強化されました。
- `bootstrap/app.php`ファイルに`withSchedule`が追加されました。
- `InvalidArgumentException.php`のcreateメソッドのドックブロックが修正されました。
- 署名のタイポが修正されました。
- `ApplicationBuilder::withSchedule()`が簡素化されました。
これらの変更は、Laravelフレームワークの機能強化、バグ修正、および使いやすさの向上に寄与しています。
#laravel
Laravelプロジェクトでの開発速度を上げるためには、Artisanコマンドラインツールを積極的に使用することをお勧めします。例えば、`php artisan make:model ModelName -mcr` コマンドを使うと、モデル、コントローラー、およびマイグレーションファイルが同時に生成され、開発プロセスを大幅に加速します。
#laravel
質問: Laravelでモデルとテーブルの関連付けをどのように行いますか?
回答: Laravelでは、モデルとデータベーステーブルを関連付けるには、モデル内でテーブル名を指定する必要があります。これは、モデル内で`$table`プロパティを設定することにより行われます。デフォルトでは、Laravelはクラス名の複数形をテーブル名として推測しますが、異なるテーブル名を使いたい場合はこのプロパティを使用して明示的にテーブル名を指定します。例えば、`User`モデルが`users_data`テーブルに関連付けられている場合、以下のようにモデルに記述します。
```php
class User extends Model
{
protected $table = 'users_data';
}
```
このようにして、モデルとテーブルの関連付けをカスタマイズできます。
#laravel
### Question:
In Laravel, how would you architect a solution for a "time-travel" feature in an application, where users can view the state of their data at any given point in the past, assuming the application uses Eloquent ORM for database operations?
### Answer:
To implement a "time-travel" feature in a Laravel application using Eloquent ORM, I would leverage the concept of temporal tables or database versioning. However, since native temporal tables support might not be available for all database types, or might be complex to implement directly, a practical Laravel-centric solution would involve creating a custom versioning system through model events and historical data tables.
Here's a high-level approach:
1. **Historical Data Tables**: For each model/table you wish to have the "time-travel" functionality, create a corresponding 'historical' table. This table will mirror the original table's schema but with two additional columns: `valid_from` and `valid_until` (timestamp or datetime columns), and a reference to the original table's primary key.
2. **Model Observers**: In Laravel, use model observers (`App\Providers\EventServiceProvider`) to hook into the lifecycle events of your models (`created`, `updated`, `deleted`). For each of these events, instead of modifying the original record, insert a new record into the historical table. The `valid_from` field represents the timestamp of the event (creation, update, etc.), and `valid_until` can initially be set to null or a far future date to denote that this version is the current one.
3. **Time-travel Query Scopes**: Within your model, define a custom query scope to retrieve the version of the model as of a particular timestamp. This scope will join the model's table with its historical table on the model's ID, filtering on records where the provided timestamp falls between the `valid_from` and `valid_until` values.
Example query scope might look like this:
```php
public function scopeAsOf($query, $timestamp)
{
return $query->leftJoin('historical_table_name', 'original_table_name.id', '=', 'historical_table_name.original_id')
->where('historical_table_name.valid_from', '<=', $timestamp)
->where(function ($query) use ($timestamp) {
$query->where('historical_table_name.valid_until', '>=', $timestamp)
->orWhereNull('historical_table_name.valid_until');
})
->select('original_table_name.*', 'historical_table_name.*') // Adjust select as necessary
->latest('historical_table_name.valid_from');
}
```
4. **Data Retrieval**: To "time-travel" and view data as it was at a certain point in time, use the aforementioned query scope, passing in the desired timestamp. This will return the state of the data at that particular moment.
This approach encapsulates the "time-travel" functionality within the application layer, providing flexibility and avoiding the reliance on database-specific features. Additionally, it offers the potential for complex historical data analysis and auditing directly through Laravel's Eloquent ORM.
#laravel
Let's talk about one of the core concepts of the Laravel framework: **Eloquent ORM**. Eloquent is an object-relational mapper that makes it a breeze to interact with your database. By using Eloquent, you can model your database tables as classes, making it much easier to query the data, insert new records, and establish relationships between different pieces of your data. The official Laravel documentation provides extensive insights into how you can utilize Eloquent to its fullest potential, but for now, let's break down some of its key concepts.
### What is Eloquent ORM?
Eloquent ORM stands for Object-Relational Mapping. In Laravel, it's a powerful implementation that provides a simple ActiveRecord implementation for working with your database. Each database table has a corresponding "Model" which is used to interact with that table.
### Defining Eloquent Models:
Models in Laravel follow the naming convention of being singular and CamelCase. For example, a database table named `users` would have a corresponding model named `User`. This model class extends `Illuminate\Database\Eloquent\Model` and doesn't need any additional code to start working with the database.
```php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
// Model body
}
```
### Retrieving Records:
Eloquent makes it really simple to retrieve records from the database. For instance, to get all users from the `users` table, you would use the `all` method:
```php
$users = App\Models\User::all();
```
This will return all the users in the `users` table as instances of the `User` model.
### Inserting and Updating Records:
Eloquent also simplifies the process of inserting and updating records. To create a new record, you might do something like:
```php
$user = new App\Models\User();
$user->name = 'John Doe';
$user->email = 'john@example.com';
$user->save();
```
Updating a record is just as simple. You first retrieve the model, then change the values, and call `save`:
```php
$user = App\Models\User::find(1);
$user->email = 'jane@example.com';
$user->save();
```
### Relationships:
One of the strongest points of Eloquent is its ability to define relationships easily. There are several types of relationships that Eloquent supports: One to One, One to Many, Many to One, and Many to Many. Defining a relationship is done by defining a method on your model that returns the relationship:
```php
public function posts()
{
return $this->hasMany(Post::class);
}
```
This example defines a One to Many relationship between the `User` and `Post` models, indicating that a user can have multiple posts.
### Conclusion:
Eloquent ORM represents a significant part of the Laravel ecosystem, providing an elegant and simple way to work with your database. Its ActiveRecord implementation allows for an eloquent and fluent interface for querying the database and managing relationships between data models. While this overview touches on the basics, the Laravel documentation offers a comprehensive exploration of what's possible with Eloquent, from advanced query techniques to eager loading and beyond.
Eloquent ORM perfectly demonstrates Laravel's philosophy of making development tasks enjoyable and efficient, without sacrificing application functionality.
#laravel