How to Redirect using two parameter in Controller using Laravel 5.5

81 Views Asked by At

Controller is :

 elseif ($profile_is_exsit > '0') 
        {
            $url = DB::table('marriage_bureau')->select('title','custom_id')->where('user_id',$user_id)->first();
            $title = $url->title;
            $custom_id = $url->custom_id;
           return redirect('marriage-bureau/{title}/{custom_id}');              
        }

This return redirect is generating Error. I need to generate a URL followed by the following route.

Routes in web.php

Route::get('marriage-bureau/{title}/{id}','marriage_bureau\ViewMarriageBureauController@index');
3

There are 3 best solutions below

1
Lizesh Shakya On BEST ANSWER

You can provide variable to the url

return redirect("marriage-bureau/{$title}/{$custom_id}");
0
Dino Numić On

You can do this

return redirect()->route('route name', ['title' => $title, 'custom_id' => $custom_id]);
0
emekamba On

In your controller use:

elseif ($profile_is_exsit > '0') 
    {
        $url = DB::table('marriage_bureau')->select('title','custom_id')->where('user_id',$user_id)->first();
        $title = $url->title;
        $custom_id = $url->custom_id;
       return redirect()->route('your-route-name', ['title' => $title, 'custom_id' => $custom_id]);             
    }

In your route use:

 Route::get('marriage-bureau/{title}/{id}', 
   [
    'uses'=>'marriage_bureau\ViewMarriageBureauController@index',
    'as'=>'your-route-name',
  ]

);