Tuesday, May 26, 2015

Contoh penggunaan facade session::

1. Simpan item dalam session :

Session::put('key', 'value'); 
 
method :
 
 session(['key' => 'value']);

2. masukkan nilan dalam item session :

Session::push('user.teams', 'developers');

3. Dapatkan item dalam session :

$value = Session::get('key'); 

method :
 
$value = session('key');

4. Dapatkan item dari session :

$value = Session::get('key', 'default'); 

atau 
 
$value = Session::get('key', function() { return 'default'; });

5. Dapatkan Item dan lupakan :

$value = Session::pull('key', 'default');

6. Datapakan semua data dari session :

$data = Session::all();

7. Pastikan item wujud dalam session :

if (Session::has('users')) { // }

8. Buang item dalam session : 

Session::forget('key');

9. Buang semua item dalam session :

Session::flush();

10. Bina id session baru :

Session::regenerate();

 


flash data : simpan data untuk request yang seterusnya.


11. Reflash data semasa untuk request seterusnya :

Session::reflash();

12. Reflash habya sebahagian Flash Data

Session::keep(['username', 'email']);



Guna database sebagai session data :

Contoh  Schema  table:
 
Schema::create('sessions', function($table)
{
    $table->string('id')->unique();
    $table->text('payload');
    $table->integer('last_activity');
});

atau
 
php artisan session:table

composer dump-autoload

php artisan migrate

2 comments:

  1. 5 Best Video Gambling Sites for 2022 - vimeo
    4.0/5.0 By the way, I recommend gambling for fun or entertainment, this site is one of the top online gambling sites. It has a youtube mp4 great sportsbook,

    ReplyDelete
  2. Slots, video poker machines, and the internet
    There's a wide range of slots, video poker machines, and 먹튀폴리스 검증업체 the 러시안 룰렛 가사 internet casinos want you 바퀴벌레 포커 to play, and the casinos don't want you to have 스보벳 to. 블랙잭사이트

    ReplyDelete