Wednesday 20 February 2019

Laravel File, Mail, Exception, UUID

use Illuminate\Support\Str;

return (string) Str::uuid();

return (string) Str::orderedUuid();



// Get file externsion

//Where $file is an instance of Illuminate\Http\UploadFile$extension = $file->getClientOriginalExtension();



// Laravel make directory using File class

        File::isDirectory($path) or File::makeDirectory($path, 0755, true, true);
        $file->move($path, $file_uuid . '.' . $file->getClientOriginalExtension());



// Email google, config in .env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=xxx
MAIL_PASSWORD=xxxx
MAIL_ENCRYPTION=tls

// Better to do a two way authentication

use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Mail;
                // Send email to shared user
                Mail::raw($email_content['message'], function ($message) use ($email_content, $email) {
                    $message->from('Sxxx@hotmail.com','SXXX title');
                    $message->subject($email_content['subject']);
                    $message->to($email);
                });
Throw the exception using the following code.
throw new \Exception("failed");
Otherwise, import the class before using.
use Exception;

No comments:

Post a Comment