raviawasti
3 months ago

How can i get the slug passed in view for vuejs components ?

Posted 3 months ago by raviawasti

Route::get('questions/{slug}', '[email protected]');

//Api for single page Route::get('post/singlePage/{slug}', '[email protected]');

public function postSingle($slug){

      if(Post::where('slug',$slug)->exists()){
      $post = Post::where('slug',$slug)->first();
      }else{
        return view('404');
      }

      return view('frontend.candidates.socialmedia.Singlepost',compact('post'));
    }



       public function postSingleAPI($slug)
{

$data['posts'] = Post::where('slug',$slug)->first(); return $data;

}

app.js var app = new Vue({ el: '#app', data() { singlePosts:[],

 };

created(){ this.singlePageApi(); },

 methods:{
 singlePageApi(){

axios.get(this.bUrl +'/post/singlePage/' + this.slug) .then(response=> { this.singlePosts=response.data; //we are putting datat into our data

}) .catch(function (error) { console.log(error);//if error }); }, } }

Singlepost.blade.php

@{{singlePosts.body}}

Please sign in or create an account to participate in this conversation.