1. Go to this page and download the library: Download tomshaw/google-api 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/ */
tomshaw / google-api example snippets
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use TomShaw\GoogleApi\GoogleClient;
use Illuminate\Http\Request;
class GoogleAuthController extends Controller
{
public function index(GoogleClient $client)
{
return $client->createAuthUrl();
}
public function callback(Request $request, GoogleClient $client)
{
$authCode = $request->get('code');
$accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
if ($accessToken) {
$client->setAccessToken($accessToken);
}
return redirect()->route('homepage');
}
}
public function add()
{
$calendar = GoogleApi::calendar()->setCalendarId('[email protected]');
$summary = 'Test Event';
$location = '123 Test St, Test City, TS';
$description = 'This is a test event.';
$from = Carbon::now()->timezone('America/Chicago')->addDay()->startOfDay()->addHours(13);
$to = $from->copy()->addHour();
$event = $calendar->addEvent($summary, $location, $description, $from, $to);
// save event id for event updates.
}
public function mount(Order $id)
{
$model = Order::with(['user'])->where('id', $id)->first();
$attachments = [
storage_path('app/public/discount.jpg'),
storage_path('app/public/invoice.pdf'),
];
$gmail = GoogleApi::gmail();
$gmail->from('[email protected]', 'Company Name');
$gmail->to($model->user->email, $model->user->name);
$gmail->cc('[email protected]');
$gmail->bcc('[email protected]');
$gmail->subject('Thank you for your order.');
$gmail->mailable(new OrderMailable($model, 'template-name'));
$gmail->attachments($attachments);
$gmail->send();
}