PHP code example of kaoken / laravel-flash-message

1. Go to this page and download the library: Download kaoken/laravel-flash-message library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kaoken / laravel-flash-message example snippets

 php

namespace app\Http\Controllers;

use FlashMessage;
use App\Library\Http\Controllers\Controller;

class Test extends Controller
{
    public function getTest01()
    {
        // 文字列のみ
        FlashMessage::pushSuccess('This is test messege');
        // 任意のオブジェクト
        $o = new \stdClass();
        $o->title = 'title 01';
        $o->text = 'text 01';
        FlashMessage::pushError($o);
        $o = new \stdClass();
        $o->title = 'title 02';
        $o->text = 'text 02';
        FlashMessage::pushError($o);

        return redirect('test02');
    }
    public function getTest02()
    {
        return view('test');
    }
}

 php
@php
  $errorMessages = $flashMessage->errors();
  $successMessages = $flashMessage->successes();
@endphp

{{--成功メッセージ--}}
@if( $flashMessage->hasSuccess() )
  <h1>成功メッセージ</h1>
  @for($i=0;$i<count($successMessages);$i++)
    <hr />
    {{$successMessages[$i]}}
  @endfor
  <hr />
@endif

{{--エラーメッセージ--}}
@if( $flashMessage->hasError() )
  <h1>エラーメッセージ-</h1>
  @for($i=0;$i<count($errorMessages);$i++)
    <hr />
    {{ $errorMessages[$i]->title }}<br />
    {{ $errorMessages[$i]->text }}<br />
  @endfor
  <hr />
@endif