Home > Software design >  Opening Laravel links based on their Id
Opening Laravel links based on their Id

Time:01-30

I've created a laravel blog and I want to open every single post on their own page using the following laravel link.

 <a href="{{route('about.show'.$about_us)}}" >{{$about_us->button}}</a> which I trying to open using the show method and the routes. This is how I have set up the show method and it's route.

public function show($id)
{
    //
    return view('about.show')
}

Route::get('/about.show','App\Http\Controllers\AboutController@show')->name('about.show');

When I try, it gives me an error Route [about.show{"id":1,"title":"My Agenda","description":"My four",... not defined.

When I try to open it up using the index method it shows but it picks up two ids. and when I delete .$about_us, it displays a blank white page. This is a noob question, but I'm struggling. Can anyone assist

CodePudding user response:

I don't know your code so that's why I am giving some example how to acheive this thing.

Route::get('/show/{id}','App\Http\Controllers\AboutController@getPostById');
public function getPostById($id){
  $request=app('request');
  $data=Model::where('id',$request->id)->get();
  return response()->json([$data]);
}
  •  Tags:  
  • Related