I have hosted my laravel application on shared server where public directory is public_html. The order invoice path should be /var/www/html/public_html/user_invoices/invoice_order_447B11621531373227.pdf
- Laravel version: 5.7
- Dompdf: "barryvdh/laravel-dompdf": "^0.9.0"
I am getting this error:
ErrorException: file_put_contents(/var/www/html/myproject/public_html/user_invoices/invoice_order_447B11621531373227.pdf): failed to open stream: No such file or directory in /var/www/html/crm/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:122
This is my mailable class:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use PDF;
class UserNotificationsOrderPlaced extends Mailable
{
public $data;
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$path = public_path('user_invoices/invoice_order_'.$this->data[0]->order_id.'.pdf');
$pdf = PDF::loadView('pdf.invoice', ['order'=>$this->data[0]])->save($path);
return $this->view('emails.orders')->with(['orders'=>$this->data])->attach($path);
}
}
AppServiceProvider:
I have tried both solutions realpath and base_path but still getting same error:
return realpath(base_path().'/../public_html');
return base_path().'/../public_html';return realpath(base_path().'/public_html');
return base_path().'/public_html';
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//Schema::defaultStringLength(191);
if (class_exists('Swift_Preferences')) {
\Swift_Preferences::getInstance()->setTempDir(storage_path().'/tmp');
} else {
\Log::warning('Class Swift_Preferences does not exists');
}
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->bind('path.public', function() {
return realpath(base_path().'/../public_html');
//return base_path().'/../public_html';
});
}
}