2016-04-23 93 views
1

我想重定向::到一個自定義的URL使用laravel中的變量,一旦我做了一些操作。這裏是我到目前爲止的代碼:插入變量到重定向::到Laravel

Route::get('remove_comment/{id}', function($id) { 
    $comment = get_comment($id); 
    $postId = $comment->Post_Id; 
    remove_comment($id); 

    return Redirect::to(url('page/{{{$postId}}}')); 
}); 

所以我希望它重定向到一個像/ post/1或類似的URL的頁面。它不起作用,我已經實現了它,但我確信會有辦法。是否有可能做我在問什麼?

+0

試試這個:'return Redirect :: to(url('page /'.$ postId));' – odannyc

回答

1

看起來像你是在你的路線內,所以使用刀片將無法工作,除非指定。此外,它已經在PHP這樣做是這樣的:

Route::get('remove_comment/{id}', function($id) { 
    $comment = get_comment($id); 
    $postId = $comment->Post_Id; 
    remove_comment($id); 

    return Redirect::to(url('page/'.$postId)); 
}); 

注意到這一行:return Redirect::to(url('page/'.$postId));

您也可以使用雙引號而不是單引號和包裝你的變量注入的變量轉換爲字符串在大括號中。所以: return Redirect::to(url("page/{$postId}"));

+0

工作,謝謝。 –