vendredi 6 janvier 2017

Use third party library in laravel

Im still learning the ropes of Laravel so pardon me if this is a simple question. I found a library I would like to use that will allow me to develop an inbox section of my application for users to check their inbox set up on third parties like gmail, etc. The library is php-imap and can be found here.

I already installed it with composer and now I can see it in my /vendor directory. I set up a view, controller called EmailController and added my route as normal. The problem is according to the documentation I should be able to use the namespace but when I do I get the error

FatalErrorException in EmailController.php line 17:
Class 'App\Http\Controllers\PhpImap\Mailbox' not found

I found this answer but it looks pretty old and is a slightly different scenerio.

Here is my EmailController:

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use PhpImap\Mailbox as ImapMailbox;
use PhpImap\IncomingMail;
use PhpImap\IncomingMailAttachment;

class EmailController extends Controller
{
    //

    public function index()
    {
        // 4. argument is the directory into which attachments are to be saved:
        $mailbox = new PhpImap\Mailbox('{imap.gmail.com:993/imap/ssl}INBOX', 'some@gmail.com', '*********', __DIR__);

        // Read all messaged into an array:
        $mailsIds = $mailbox->searchMailbox('ALL');
        if(!$mailsIds) {
            die('Mailbox is empty');
        }

        // Get the first message and save its attachment(s) to disk:
        $mail = $mailbox->getMail($mailsIds[0]);

        var_dump($mail);
        echo "\n\n\n\n\n";
        var_dump($mail->getAttachments());
    }
}

How would I go about adding and using third party libraries in laravel?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2iS0rxL
via IFTTT

Aucun commentaire:

Enregistrer un commentaire