0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Laravel】セッションのforgetとremoveの違い

Posted at

vendor/laravel/framework/src/Illuminate/Session/Store.phpに定義元があります。

  • remove
/**
 * Remove an item from the session, returning its value.
 *
 * @param  string  $key
 * @return mixed
*/
public function remove($key)
{
   return Arr::pull($this->attributes, $key);
}
  • forget
/**
 * Remove one or many items from the session.
 *
 * @param  string|array  $keys
 * @return void
*/
public function forget($keys)
{
   Arr::forget($this->attributes, $keys);
}

どちらもArrファサードの削除処理で、違いは返り値の有無

返り値

  • remove
session()->put('testSession', 'テストセッション');
session()->remove('testSession'); // テストセッション
  • forget
session()->put('testSession', 'テストセッション');
session()->forget('testSession'); // null

removeだと返り値でsessionの中身が返るので、条件文とかに使えそうかも

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?