代码之家  ›  专栏  ›  技术社区  ›  Hemant Kumar

Laravel将公共目录更改为public_html

  •  0
  • Hemant Kumar  · 技术社区  · 5 年前

    我在共享服务器上托管了我的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';
            });
      }
    }
    
    0 回复  |  直到 5 年前
        1
  •  0
  •   Raja Tayyab Janjua    5 年前

    您需要创建一个路由来清除服务器上的缓存

    Route::get('/clear-cache', function() {
        $exitCode = Artisan::call('cache:clear');
        $exitCode = Artisan::call('config:cache');
        return 'DONE'; //Return anything
    });
    
        2
  •  0
  •   Hemant Kumar    5 年前

    解决了的:

    我已经手动删除了缓存中的所有内容,但它不起作用。 这有助于我解决这个问题。

    Laravel showing "Failed to clear cache. Make sure you have the appropriate permissions"

    最后,php artisan cache:clear与上述解决方案配合使用。

    推荐文章