samedi 28 juillet 2018

laravel-toast code at Controller

I'm trying to add laravel-toast using his code https://github.com/Grimthorr/laravel-toast

I wrote like this (error case)

if ($validator->fails()) {

                return redirect('/')->with($notification);
                    ->withInput()
                    ->withErrors($validator)

            // I add this below line but didn't work                        
                    ->withErrors($notification = array(
                    'message' => 'error' ,
                    'alert-type' => 'error'));

                }

And this is success case

$books = new Book;
        $books->item_name = $request->item_name;
        $books->item_number = $request->item_number;        
        $books->save();

        $notification = array(
                'message' => 'success' ,
                'alert-type' => 'success'
            );
    return redirect('/')->with($notification);

Here is my blade file

<script>
    @if(Session::has('message'))
    var type=""

    switch(type){
    case 'error':
    toaster error("");
    break;

    case 'success':
    toaster success("");
    break;
}
@endif
</script>

Tost didn't show up I thought Controller code is looks wrong... Could somebody correct my code please.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2uUF9og
via IFTTT

Aucun commentaire:

Enregistrer un commentaire