PHP code example of swandoola / laravel-gmail

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

    

swandoola / laravel-gmail example snippets


Route::get('/oauth/gmail', function (){
    return LaravelGmail::redirect();
});

Route::get('/oauth/gmail/callback', function (){
    LaravelGmail::makeToken();
    return redirect()->to('/');
});

Route::get('/oauth/gmail/logout', function (){
    LaravelGmail::logout(); //It returns exception if fails
    return redirect()->to('/');
});

$messages = LaravelGmail::message()->subject('test')->unread()->preload()->all();
foreach ( $messages as $message ) {
    $body = $message->getHtmlBody();
    $subject = $message->getSubject();
}
 php
'providers' => [
    Swandoola\LaravelGmail\LaravelGmailServiceProvider::class,
]
 php
'aliases' => [
    'LaravelGmail' => Swandoola\LaravelGmail\Facade\LaravelGmail::class,
]
 php
    
    LaravelGmail::message()
                ->from('[email protected]')
                ->unread()
                ->in('TRASH')
                ->hasAttachment()
                ->all()
 php
    
    LaravelGmail::message()
                ->from('[email protected]')
                ->unread()
                ->in('TRASH')
                ->hasAttachment()
                ->preload()
                ->all()