PHP code example of sangamkatwal / sangam-toastr

1. Go to this page and download the library: Download sangamkatwal/sangam-toastr 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/ */

    

sangamkatwal / sangam-toastr example snippets


// Success notification
return redirect()->back()->with([
    'success' => true,
    'message' => 'Data saved successfully!'
]);

// Error notification
return redirect()->back()->with([
    'error' => true,
    'message' => 'Something went wrong!'
]);

// Multiple messages (arrays supported)
return redirect()->back()->with([
    'error' => true,
    'message' => ['Field is 

// Success response
return response()->json([
    'success' => true,
    'message' => 'Operation completed!'
]);

// Error response
return response()->json([
    'error' => true,
    'message' => 'Validation failed!'
]);

public function store(Request $request)
{
    try {
        // Your logic here...
        
        $message = 'Record created successfully!';
        
        return $request->ajax()
            ? response()->json(['success' => true, 'message' => $message])
            : redirect()->back()->with(['success' => true, 'message' => $message]);
            
    } catch (Exception $e) {
        $message = 'Something went wrong!';
        
        return $request->ajax()
            ? response()->json(['error' => true, 'message' => $message])
            : redirect()->back()->with(['error' => true, 'message' => $message]);
    }
}
bash
# Publish everything
php artisan vendor:publish --tag=sangam-toastr

# Or publish separately
php artisan vendor:publish --tag=sangam-toastr-assets
php artisan vendor:publish --tag=sangam-toastr-views