このパッケージを実装しようとしています。https://github.com/vinkla/hashids URLのすべてのIDをobsfucateします。Laravel 5.2ルートモデルのバインドエラーによりSQLの不明な列エラーが発生しました
私は
Route::bind('id', function ($id, $route) {
return Hashids::decode($id)[0];
});
Route::resource('orange', 'OrangeController');
Route::model('orange', 'App\Orange');
Iをroutes.php-するには、以下の追加の新鮮なlaravel 5.2のインストールを作成し、テーブルにpopulated-
INSERT INTO `oranges` (`id`, `orange_name`) VALUES(1, 'test1'),(2, 'test2'),(3, 'test3');
をOrange.phpと呼ばれる一つのモデルを作成しましたまた、Orange.phpに次の関数を追加することによってgetRouteKeyをオーバーライドしました。
public function getRouteKey()
{
return Hashids::encode($this->getKey());
}
getRouteKey sh ouldはURLを表示するためにIDをエンコードします。例えば3がhgfdhに行くと、私のルートバインディングはidパラメータを使って任意のルートに 'id'ワイルドカードを介して適用され、この場合OrangeController.phpのIDをデコードします。
私はそれが代わりの$のIDのオレンジのインスタンスをバインドしようとしているhttp://localhost:8000/orange/3-
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'orange_name:"test3"' in 'where clause'
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'orange_name:"test3"' in 'where clause' (SQL: select count(*) as aggregate from `oranges` where `orange_name` = test3 and `orange_name:"test3"` <> {"id":3 and `created_at:"2016-06-23 09:30:39"` = updated_at:"2016-06-23 09:30:39"})
をロードしようとしたとき、私はこのエラーが
Route::model('orange', 'App\Orange');
ツー関係だと思い、次の2つのエラーを受け取りましたオレンジ?もしそうなら、私は$ idにバインドできますか?
私はルート::モデル定義をコメントアウトした場合、私はLaravelは"route-model"結合機構を有している
NotFoundHttpException in Handler.php line 103:
No query results for model [App\Orange].
ありがとうございます。リンクありがとう。前に見ましたが、このhttps://github.com/Propaganistas/Laravel-FakeIdパッケージに関する新しいコメントがありました。 – user4074875