学习laravel遇到的一些错误

博主运行环境:windows 7、homestead、laravel5.2

参考教程:

安装及快速上手教程:环境配置及快速上手-Gold3bear创新设计师

系列教程:laravist-JellyBool

PDOException SQLSTATE[HY000] [2002] No such file or directory

《学习laravel遇到的一些错误》

原因:根目录.env的host忘记配置

解决方法:

APP_ENV=local

APP_DEBUG=true

APP_KEY=yYAZu4SpKTkUij6g6qNTNsLvZ0jaRvIA

DB_HOST=192.168.10.10

DB_DATABASE=homestead

DB_USERNAME=homestead

DB_PASSWORD=secret

laravel5.2 Forms & HTML

问题:

初学,照教程composer一个叫illuminate/html的Package,使用中发现不能用,并且composer update的时候会抛出错误:

[Symfony\Component\Debug\Exception\FatalErrorException]

Call to undefined method Illuminate\Foundation\Application::bindShared()

原因:

网上查到说5.1以后不支持了,然后就移除illuminate/html在config/app.php中的配置项,

providers中的

‘Illuminate\Html\HtmlServiceProvider’

aliases中的

‘Form’      => ‘Illuminate\Html\FormFacade’,

‘HTML’      => ‘Illuminate\Html\HtmlFacade

再执行

composer remove illuminate/html

composer update

解决

5.1以后用laravelcollective/html 这个package替换了。

composer require laravelcollective/html

在/config/app.php的providers数组中添加下面的这句

‘providers’=>[

// …

Collective\Html\HtmlServiceProvider::class,

// …

],

在/config/app.php的aliases数组中添加下面的这两句

‘aliases’=>[

// …

‘Form’=>Collective\Html\FormFacade::class,

‘Html’=>Collective\Html\HtmlFacade::class,

// …

],

代码书写格式

{!!Form::open(array(‘url’=>’foo/bar’))!!}

//

{!!Form::close()!!}

更多请看:laravelcollective/html

3、laravel5.2 $errors未定义

在如下的view中

@if($errors->any())

@foreach($errors->all() as $error)

{{ $error }}

@endforeach

@endif

运行结果,显示说errors未定义

ErrorExceptionin914a2f40c2a0260aead9a841feca0bfaaa75619c.php line 24:Undefined variable: errors (View: /home/vagrant/Code/laravel-master/resources/views/articles/create.blade.php)

解决方法:

原rotes.php

Route::get(‘/’,’ArticleController@index’);

Route::get(‘article/create’,’ArticleController@create’);

Route::post(‘article/store’,’ArticleController@store’);

Route::get(‘articles/{id}’,’ArticleController@show’);

改为

Route::group([‘middleware’ => [‘web’]], function () {

     Route::get(‘/’,’ArticleController@index’);

     Route::get(‘article/create’,’ArticleController@create’);

     Route::post(‘article/store’,’ArticleController@store’);

    Route::get(‘articles/{id}’,’ArticleController@show’);

});

原因

应该是$errors从默认的全局中间件移到了web中间件中。

参考:segmenfault

    原文作者:皮丘吉尔
    原文地址: https://www.jianshu.com/p/e00d9086aa2d
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞