Posts

Showing posts from September, 2022

How to send an attachment from request to mail without first saving it to storage?

How to send an attachment from request to mail without first saving it to storage? public function build(){      $email = $this->from('mymail@gmail.com')                            ->view('emails.contact');        foreach(request()->file() as $file) {                    $email->attach($file->getRealPath(), [                   'as' => $file->getClientOriginalName(),                   'mime' => $file->getMimeType(),          ]);      } } return $email; You can see it in the documentation https://laravel.com/docs/9.x/mail#attachments

Check Laravel JWT token is valid or not

Create Middleware using the below command Command: php artisan make:middleware JwtMiddleware Paste the below code: <?php namespace App\Http\Middleware; use Closure; use JWTAuth; use Exception; use Tymon\JWTAuth\Http\Middleware\BaseMiddleware; class JwtMiddleware extends BaseMiddleware {     /**      * Handle incoming requests.      * @param  \Illuminate\Http\Request  $request      * @param  \Closure  $next      * @return mixed      */     public function handle($request, Closure $next)     {         try {             $user = JWTAuth::parseToken()->authenticate();         } catch (Exception $e) {             if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenInvalidException){                 return response()->json(['st...

Laravel: Transform Request to custom validation request

Laravel: Transform Request to custom validation request we can convert any request to any other request, as long as it extends from Illuminate\Http\Request. There are basically two methods Laravel uses to convert one request to another. The problem here is that it will never get a validation object or trigger the validation automatically, as part of the injection when MyRequest  was passed as an argument. It might also miss a message bag and the error handler, but nothing you can fix by initializing the request just like Laravel does when injecting it. So you still have to trigger all the sequences the FormRequest (if it extends FromRequest rather than Request) normally does when booting the trait, but still, it's entirely possible and with some little extra work, you could convert any request to any other request. For example; I'm using this setup to call just one route profile/{section}/save for saving my profile settings. Depending on $section's value, I convert the give...

Git Cheatsheet

Image
Hello everyone, here is a quick reference guide of the git commands: git config Setup author name and mail to be used for all commits in current repository, Devs commonly use  --global flag  to set config options for current user. git config --global user.name "username" git config --global user.email "usermail@example.com" git clone Clone the remote repository with HTTPS or with SSH. This should create a new child directory for the project sources. git clone <REPO CLONE URL> git status Shows the status of your current branch. It will tell you which files you have modified, which files are stages for commit and which files are not. It will also let you know if your local branch is behind, or not up to date with, its remote tracking branch. This command is particularly useful in combination with  git add  when you only want to commit certain files. git branch Create a branch, or show a list of local or remote branches. With git branch, you can add options to do...