LoginSignup
18
18

More than 5 years have passed since last update.

年末にLaravel5で開発しててハマったところメモ

Last updated at Posted at 2014-12-28

対象者

Laravel4.xで使っていたソースをLaravel5に移植したら動かなくなった人
※Laravel5は12/28現在、開発版のため情報の取り扱いには注意してください。

Paginationのlinksメソッドがない!

エラー内容

linksメソッドなんてないぞというエラーが出る

ErrorException in AbstractPaginator.php line 432:
call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\Support\Collection' does not have a method 'links' (View: /vagrant/resources/templates/article/list.blade.php)

解決方法

links()ではなく、render()を使う

resources/templates/article/list.blade.php
- {!! $articles->links() !!}
+ {!! $articles->render() !!}

参考:Laravel 5 pagination

問題を起こしたソースコード

resources/templates/article/list.blade.php
{!! $articles->links() !!}
App/Http/Controllers/ArticleController

[中略]

public function showList() {

    // 記事を取得する
    $articles = Article::paginate(10);

    /*---------------------*/
    /* Viewへ渡すデータを構築 */
    /*---------------------*/
    $aryViewAssign = array();
    $aryViewAssign['articles'] = $articles;

    // Viewをレンダリング
    return view('article/list', $aryViewAssign);
}

ヘルパー関数:link_toメソッドがない!

エラー内容

Call to undefined function link_to()

解決方法

HtmlとFormのFacadeがないため。
-> フレームワークのコアモジュールから削除されたのでデフォルトでは入っていない。composer.jsonとかに記述して手動で追加する。

composer.json
"require": {
    "laravel/framework": "~5.0",
    "illuminate/html": "~5.0", <- これを追加
}
config/app.php
'providers' => [



    'Illuminate\Html\HtmlServiceProvider', 
],

'aliases' => [



    'Form' => 'Illuminate\Html\FormFacade',
    'Html' => 'Illuminate\Html\HtmlFacade',
]

問題を起こしたソースコード

resources/templates/article/list.blade.php
{!! link_to("article/edit/$article->id", "編集", $attributes = array(), $secure = null) !!}

以下、随時ハマったところ追加予定

18
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
18