1 month ago

From blade to vue

Posted 1 month ago by KikoLdasd

Hi, I have a more delicate question, if you can help me. I want to send the data from the blade, that is, everything I have in the blade to send to a page in view. I have the vue component in the same laravel directory and I would like to know the following: How can I get the data with get and also send with post? Can you help me? It's urgent Vue component:

   <div class="container">
      <div class="d-flex justify-content-center">
         <div class="col-md-12">
            <div class="error-template">
               <h1 align="center">
               <h2 align="center">
                  Questionnaire Website
   export default {
       mounted() {
           console.log('Component mounted.')
<style lang="scss"></style>

Laravel blade:

<div class="container">
   <h4 class="container d-flex justify-content-center"><i class="fa fa-question"></i>Questionnaire</h4>
   <div class="d-flex justify-content-center">
      <ul class="list-group">
         @foreach($questions as $question)
         <li class="list-group-item">{{ $question->questiontype }}</li>
         <a href="vote/{{ $question->id }}" class="btn btn-outline-primary">vote</a>
         <span class="badge badge-primary"><strong>{{ $question->votes }} results</strong></span>
      <div class="card">
         <div class="card-body">
            <h1 align="center">Votes</h1>
            @foreach($percentage as $row)
            <span class="badge badge-primary"><strong?>{{ $row->questiontype }}: {{ intval($row->percentage) }}%</strong></span>
My controller;

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Auth;
use DB;
use App\Question;
use App\Answer;
use Alert;

class QuestionController extends Controller
    public function show() {
		if(Auth::check()) {
			$questions = DB::table('questions')->paginate(10);
			$percentage = \DB::table('questions')
				\DB::raw('(sum(`votes`) / (select sum(`votes`) from `questions`) * 100) as percentage')
			return view('home', compact('questions', 'percentage'));
		return redirect('register');

    public function vote(Request $request, $id) {
    	$question = Question::find($id);
    	$question->increment('votes', 1);
		$question->increment('totalvotes', 1);
		Alert::success("Success", 'Your vote has been added');
    	return back();

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