将url作为参数传递给路由的最佳方法

时间:2018-02-12 20:26:33

标签: laravel

我正在尝试将任何完整的url作为参数传递给路由,但是斜杠似乎弄乱了所有内容。如果路由以编码方式传递,则路由似乎对其进行解码,是否有办法停止此操作或在路由级别再次编码URL?

path

我也累了

mix phx.routes

但如果它在网址中遇到问号,则会在问号后删除任何内容。

2 个答案:

答案 0 :(得分:0)

我会推荐Jeunes的答案,但是如果你仍然想要一个路由参数,你可以做base64编码/解码。这不会成为一个漂亮的网址。

JS

btoa("http://someurl.test")

PHP

Route::get('url/{url}', function ($url) {
    return base64_decode($url);
});

答案 1 :(得分:0)

检查出来

@JvmStatic
fun isInPortraitMode(activity: Activity): Boolean {
    val currentOrientation = getCurrentOrientation(activity)
    return currentOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || currentOrientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT
}

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
@JvmStatic
fun getCurrentOrientation(context: Context): Int {
    //code based on https://www.captechconsulting.com/blog/eric-miles/programmatically-locking-android-screen-orientation
    val windowManager = context.getSystemService(Service.WINDOW_SERVICE) as WindowManager
    val display = windowManager.defaultDisplay
    val rotation = display.rotation
    val size = Point()
    display.getSize(size)
    val result: Int//= ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
    if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) {
        // if rotation is 0 or 180 and width is greater than height, we have
        // a tablet
        if (size.x > size.y) {
            if (rotation == Surface.ROTATION_0) {
                result = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
            } else {
                result = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
            }
        } else {
            // we have a phone
            if (rotation == Surface.ROTATION_0) {
                result = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
            } else {
                result = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT
            }
        }
    } else {
        // if rotation is 90 or 270 and width is greater than height, we
        // have a phone
        if (size.x > size.y) {
            if (rotation == Surface.ROTATION_90) {
                result = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
            } else {
                result = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
            }
        } else {
            // we have a tablet
            if (rotation == Surface.ROTATION_90) {
                result = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT
            } else {
                result = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
            }
        }
    }
    return result
}

示例:http://myapp.test/url/http://try.me.com打印

  

http://try.me.com