laravel5的坑


以此記錄學習laravel的一些問題

 

問題:laravel轉移文件夾到另外一pc或者環境后訪問出現500

設置權限為777

 

問題: 設置路由后頁面總是404 not found

解決:需要在apache 配置文件里添加對laravel文件夾的訪問

<Directory "D:\WAMP\laravel\public">
    Options Indexes FollowSymLinks
    #

    # AllowOverride controls what directives may be placed in .htaccess files.

    # It can be "All", "None", or any combination of the keywords:

    #   Options FileInfo AuthConfig Limit

    #此處必須為all none不行

    AllowOverride All
    #

    # Controls who can get stuff from this server.

    #

    #Require all granted

    #Allow Order not supported

    Allow from all 

    Require all granted 

</Directory>

 

 

問題:Laravel 5.1Form組建不能安裝

解決辦法:

先在composer.jsonrequire中加入"laravelcollective/html": "~5.1"

然后composer update

然后config/app.php中加入

 

providers部分

Collective\Html\HtmlServiceProvider::class,

 

aliases部分

'Form' => Collective\Html\FormFacade::class,

'Html'      => Collective\Html\HtmlFacade::class,

  

問題: Laravel 5.1不能發郵件

解決

1. 設置mail.php后刪除了evn(), evn表示讀取.evn的變量

dd(Config::get('mail'));

2. 輸出配置來查看, 更新一次就要清一次cache

php artisan cache:clear

php artisan config:cache

3. 設置成ssl驗證

 

我的配置:

array:9 [▼

  "driver" => "smtp"

  "host" => "smtp.163.com"

  "port" => 465

  "from" => array:2 [▼

    "address" => "EMAIL@163.com"

    "name" => "DC"

  ]

  "encryption" => "ssl"

  "username" => "EMAIL@163.com"

  "password" => "PASSWORD"

  "sendmail" => "/usr/sbin/sendmail -bs"

  "pretend" => false

]

發現最近自己解決問題時候總是太急, 結果忽視了應該注意到的地方, 比如輸出配置一直也沒好好看, 后來仔細看才發現username, password是空導致的問題...

"聰明人用笨辦法", 還真是, 更何況咱還不聰明...

有時候慢未必就會慢.

  

問題: 怎么手動清理配置緩存

解決: 命令行可以用php artisan config:cache 

手動可以寫個路由, 然后

use Artisan;

public function clearConfigCache() {

    Artisan::call('config:cache');

}

 

問題:Laravel安裝后訪問錯誤, 或訪問routeview失效,顯示了空白頁面

解決:

chgrp -R www-data /var/www/laravel  //用戶組根據自己的來定義

chmod -R 775 /var/www/laravel/app/storage

 

外鍵約束字段必須是int 10 UNSIGNED 屬性

如果遇到各種莫名奇怪的問題, 清緩存先!!

  

 

問題:composer 不能安裝

with這條命令:

    php -r "readfile('https://getcomposer.org/installer');" | php

先進入https://getcomposer.org/installer會下載到一個文件名為installer的文件

 

然后運行php -r "readfile('/www/xx/installer');" | php來讀取下載好的文件

 

然后會生成一個composer.phar的文件, 在此文件的目錄中運行:

php composer.phar

來執行composer相關命令, php composer.phar update

 

如果php不在環境變量里, 則需要寫完整bin路徑/opt/php/bin php來替代php

 

ex:

/opt/lampp/bin/php artisan config:cache

  

問題:ajax請求時出現token missing錯誤

HTML中設置

<meta name="csrf-token" content="{{ csrf_token() }}" />

 

ajax代碼前設置

                $.ajaxSetup({

                    headers: {

                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')

                    }

                });

  

 

 

 

不錯的參考資料:

手冊: http://cheats.jesse-obrien.ca/

 

https://github.com/jp7internet/laravel-apz

https://github.com/yccphp/laravel-5-blog

http://9iphp.com/web/laravel

https://phphub.org/topics/804

http://segmentfault.com/a/1190000002505703#articleHeader6

https://phphub.org/topics/537

http://changziming.com/blog/post-167.html

權限解決方案Entrust http://www.poloo.org/?p=1057

http://ofcss.com/2015/03/13/laravel-5-custom-error-pages.html

 

里面有學習視頻link http://www.slideshare.net/shengyou/laravel-43453376


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM