PHP code example of crudadmin / autoajax

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

    

crudadmin / autoajax example snippets


public function store()
{
    //...

    return autoAjax()->success('Thank you! Your for has been successfully sent.');
}

//...

//Script dies here
autoAjax()->success('Thank you! Your for has been successfully sent.')->throw();

//...

//Success messages.
autoAjax()->success('Success message');
autoAjax()->message('Success message');
autoAjax()->save(); //Global success message will be applied.

//Error messages
autoAjax()->error('Error message with 200 HTTP code');
autoAjax()->error('Error message with 500 HTTP code', 500);
autoAjax()->error('Error message with 500 HTTP code')->code(500);
autoAjax()->error(); //Global error message will be applied.

//Change title of response
autoAjax()->message('Success message')->title('My response title');
autoAjax()->error('Error message')->title('My response title');

//Change HTTP code
autoAjax()->message('My message')->code(500);

//If you want redirect/reload request after response comes. (autoAjax.js will handle it)
autoAjax()->redirect('https://google.com');
autoAjax()->reload();

//If you need run own JS callback after response
autoAjax()->title('This is my message')->callback('alert(1)');

//If you want modify all success/error messages globally. You can do it in AppServiceProvider or somewhere else in your app configuration like that.
autoAjax()->setGlobalMessage('success', 'Changes has been successfully saved.');
autoAjax()->setGlobalMessage('error', 'Something went wrong. Try again later.');

Validator::make($request->all(), [
    'title' => '

autoAjax()->throwValidation([
    'username' => 'Validation message for username',
    'password' => 'Validation message for password',
]);