PHP code example of monicahq / laravel-sabre

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

    

monicahq / laravel-sabre example snippets

 php
use Illuminate\Support\ServiceProvider;
use LaravelSabre\Http\Auth\AuthBackend;
use LaravelSabre\LaravelSabre;
use Sabre\CardDAV\Plugin as CardDAVPlugin;
use Sabre\DAV\Auth\Plugin as AuthPlugin;
use Sabre\DAVACL\PrincipalBackend\PDO as PrincipalBackend;
use Sabre\DAVACL\PrincipalCollection;

class DAVServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        LaravelSabre::nodes(function () {
            return [new PrincipalCollection(new PrincipalBackend(/* ... */))];
        });

        LaravelSabre::plugins(function () {
            yield new AuthPlugin(new AuthBackend());
            yield new CardDAVPlugin();
        });
    }
}
 sh
php artisan vendor:publish --tag=laravelsabre-config
 sh
php artisan vendor:publish --provider="LaravelSabre\LaravelSabreServiceProvider"
 php
'methods' => ['GET', 'HEAD', 'OPTIONS', 'PROPFIND', 'REPORT', 'SEARCH'],
 php
LaravelSabre::auth(function ($request) {
    return $request->user()?->email === '[email protected]';
});
 php
LaravelSabre::principal(function ($user) {
    return 'uid/'.$user->getKey();
});