dimanche 28 février 2016

laravel : redirect()->back()->with() not sending any messages

I did as directed according to the answer provided to this question but it didn't work for me . So i reasked this question. my controller is

public function save() {

        $med_group = MedicineGroup::create(Request::all());

        if ($med_group) {
            $this->setServerMessage('MedicineGroup created successfully');
            return Redirect::to('admin/user/create')->with('flashmessage',$this->getServerMessage());

        }
    }

I have made setServerMessage() and getServerMessage() in Controller.php

public function setServerMessage($messagearray) {
        if (is_array($messagearray)) {
            $type = $messagearray['type'];
            $html = "<div style='height:auto;padding:7px 0px 6px 20px;margin:0px' class = 'pull-left text-left col-md-8 alert alert-{$type}'>{$messagearray[0]}</div>";
        } else {
            $html = "<div style='height:33px;padding:7px 0px 6px 20px;margin:0px' class = 'pull-left text-left col-md-8 alert alert-info'>{$messagearray}</div>";
        }
        $temp = '';
        if (\Session::get('SERVER_MESSAGE')) {
            $temp = \Session::get('SERVER_MESSAGE');
        }
        \Session::put('SERVER_MESSAGE', $temp . $html);
    }

public function getServerMessage() {

        if (\Session::get('SERVER_MESSAGE')) {
            $temp = \Session::get('SERVER_MESSAGE');
            \Session::forget('SERVER_MESSAGE');
            return $temp;
        } else
            return "";
    }

my view is setup like this

<div class="box-footer text-right">
                @include('flash')
                <input type="submit" class="btn btn-success" value='Save'>
                <input type="reset" class="btn btn-primary" value='Reset' />
                <a href="#" class="btn btn-danger">Cancel</a>
            </div>

and in my flash.blade.php i have written

@if(isset($flashmessage))
   {!! $flashmessage !!}
@endif

what did I miss? i followed this site too but i can't flash a message in my view.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire