Friday, March 10, 2017

Script Alert not popup in Laravel 5.4

I developed laravel 5.4 for file upload.if i upload it need to pop up te sucess alert but it is not appear in here.

Here is my Layout in Laravel 5.4

  <!DOCTYPE html>
<html lang="">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- CSRF Token -->
    <meta name="csrf-token" content="">

    <title></title>

    <!-- Styles -->
    <link href="" rel="stylesheet">

    <!-- Scripts -->
    <script>
        window.Laravel = {!! json_encode([
            'csrfToken' => csrf_token(),
        ]) !!};
    </script>
</head>
<body>
        @yield('content')
    </div>
    <!-- Scripts -->
    <script src=""></script>

</body>
</html>

Here is the UploadController`s necessary part

else if($validator -> passes()){
        if(Input::file('filenam')->isValid()){
            $extention=Input::file('filenam')->getClientOriginalExtension();
            $filename=rand(11111,99999).'.'.$extention;

            $destinationPath='up_file';
            $file->move($destinationPath, $filename);

            $notification = array(
                'message' => 'File Uploaded Successfully',
                'alert-type' => 'success'
                );

            return Redirect::to('upload')->with($notification);
        }
        else{
            $notification = array(
                'message' => 'File is not Valid!',
                'alert-type' => 'error'
                );

            return Redirect::to('upload')->with($notification);

as well as here is the view`s script part

    <script>
    @if(Session::has('message'))
    var type ="";
    switch(type){
        case 'success':
        toastr.success("");
        break;

        case 'error': 
        toastr.error("");
        break;
    }
    @endif
</script>

Can anyone suggest the problem here. Thank you.



via Dasun

Advertisement