Reputation: 320
I am trying to redirect to another page but unfortunately, it's not working How can I redirect from one page to another page please help me thanks.
Database table
Navigation table
https://ibb.co/9tBqVpr
HTML view
@foreach($Navigation as $Navi)
<li class="nav-item ">
<a class="nav-link " href="{{$Navi->slug}}">{{$Navi->Nav_menu}}</a>
</li>
@endforeach
controller
public function whatwedo()
{
$data=([
'Navigation'=>Navigations::where('slug',$slug)->first(),
]);
return view('front_end.what_we_do',$data);
}
ROUTE
Route::get('/','HomeController@index');
Route::get('whatwedo','HomeController@whatwedo');
Route::get('testimonal','HomeController@testimonal');
Route::get('product','HomeController@product');
Route::get('contact_us','HomeController@contact_us');
Upvotes: 0
Views: 169
Reputation: 4826
I this you have to use consider basics in Laravel
Use Blade view not a HTML and use url() or route() and
use different slug for all routes as per your route is not going to work
@foreach($Navigation as $Navi)
<li class="nav-item ">
a class="nav-link " href="{{ url('testimonal/'.$Navi->slug)}}">{{$Navi->Nav_menu}}</a>
</li>
@endforeach
if use you function like this
public function testimonal($slug)
{
$data = Navigations::where('slug',$slug)->first();
return view('front_end.testimonial',['data'=>$data]);
}
Route::get('testimonal/{sulg}','HomeController@testimonal');
and if you have plan to redirect this route from another function like you did
public function whatwedo($slug)
{
$data = Navigations::where('slug',$slug)->first();
return redirect('testimonal')->with(['data'=>$data]);
}
Upvotes: 0
Reputation: 4033
You can use
redirect(url('route_name'));
or
return Redirect::route('route_name')->with( ['data' => $data] );
Upvotes: 0
Reputation: 5682
You can use
return redirect()->route('route.name', [$param]);
Reference: Laravel -> HTTP Redirects
Upvotes: 1