我在共享服务器上托管了我的laravel应用程序,其中公共目录是public_html。订单发票路径应为
/var/www/html/public_html/user_invoices/invoice_order_447B11621531373227.pdf
-
Laravel版本:5.7
-
DOMDF:“barryvdh/laravel DOMDF”:“^0.9.0”
我得到了这个错误:
错误例外:
文件内容(/var/www/html/myproject/public_html/user_invoices/invoices_order_447B11621531373227.pdf):
无法打开流:中没有此类文件或目录
/var/www/html/crm/vendor/laravel/framework/src/light/Filesystem/Filesystem。菲律宾:122
这是我的邮件类:
<?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:
我尝试过realpath和base_path这两种解决方案,但仍然出现相同的错误:
返回realpath(base_path().//公共(html);;
返回基本路径()/公共_html';
返回realpath(base_path()。'/公共(html);;
返回基本路径()/公共_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';
});
}
}