msslgomez

msslgomez

Member Since 2 Months Ago

Experience Points
1,990
Total
Experience

3,010 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
0
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 1
1,990 XP
Jan
22
6 days ago
Activity icon

Awarded Best Reply on Vue Component Interact With Page Where Its In

This is the answer I got on stackOverflow

In your editComment and openReply methods you would fire events like this:

openReply(row) {
this.$emit('openReply', {any payload that you would want pass to parent});
},
editComment(item) {
this.$emit('editComment', {any payload that you would want pass to parent}
},

And, in your parent component / page you would subscribe and handle those events. Pseudo-code below:

<Comment v-on:openReply="handleOpenReply"
         v-on:editCommnet="handleEditComment"/>
Activity icon

Replied to Vue Component Interact With Page Where Its In

This is the answer I got on stackOverflow

In your editComment and openReply methods you would fire events like this:

openReply(row) {
this.$emit('openReply', {any payload that you would want pass to parent});
},
editComment(item) {
this.$emit('editComment', {any payload that you would want pass to parent}
},

And, in your parent component / page you would subscribe and handle those events. Pseudo-code below:

<Comment v-on:openReply="handleOpenReply"
         v-on:editCommnet="handleEditComment"/>
Activity icon

Started a new Conversation Vue Component Interact With Page Where Its In

I'm using 2 components in my page, one for a comment and inside the comment component is the comment reply component, I did it this way to add some functionality that I needed but now I don't know how to get the buttons in the components to do the stuff they did before I turned them into components. For example the edit function opens a dialog that is in the page where the comment component is located but now it doesn't do anything, same with the reply functionality.

How can I get this to work, or is there a way to keep those methods in the main page and not have to put them in the components? I've never made my own component before so I'm not sure how to do this.

This is the Comment component code, the editComment and openReply are methods from the main page

<template>
    <div class="comment">
        <el-card shadow="never" v-if="comment.parent_id === null">
            <el-row v-if="comment.deleted === 0">
                <el-row style="margin-bottom: 15px">
                    <el-col :span="20" v-if="forum.anonymous === 0">
                        <p class="comment-user-name">{{comment.user.name}} dice: </p>
                    </el-col>
                    <el-col :span="20" v-if="forum.anonymous === 1">
                        <p class="comment-user-name">Anónimo dice: </p>
                    </el-col>

                    <el-col :span="4">
                        <div style="text-align: end"
                             v-if="comment.user_id === $page.auth.user.auth.user.id">
                            <div v-if="canEdit" class="btn-link-edit action-button"
                                 @click="editComment(comment)">
                                <i class="fas fa-pencil-alt"></i>
                            </div>
                            <div class="btn-link-delete action-button"
                                 @click="remove(comment.id)">
                                <i class="fas fa-trash"></i>
                            </div>
                            <div class="btn-link-preview action-button"
                                 @click="openReply(comment)">
                                <i class="fas fa-reply"></i>
                            </div>
                        </div>
                        <div style="text-align: end"
                             v-if="comment.user_id !== $page.auth.user.auth.user.id">
                            <div class="btn-link-preview action-button"
                                 @click="openReply(comment)">
                                <i class="fas fa-reply"></i>
                            </div>
                        </div>
                    </el-col>
                </el-row>
                <el-row style="margin-top: 10px">
                    <p class="comment-comment">{{comment.comment}}</p>
                </el-row>
                <el-row class="fa-pull-right pb-1">
                    <p class="comment-user-time ">{{formatDate(comment.comment_time)}}</p>
                </el-row>
            </el-row>
            <el-row v-if="comment.deleted === 1">
                <el-row style="margin-top: 15px">
                    <p class="comment-comment">{{comment.comment}}</p>
                </el-row>
                <el-row class="fa-pull-right pb-1">
                    <p class="comment-user-time ">{{formatDate(comment.comment_time)}}</p>
                </el-row>
            </el-row>

            <el-row style="margin-left: 30px">
                <div v-for="reply in comment.replies">
                    <ReplyComponent :reply="reply" :forum="forum"/>
                </div>
            </el-row>
        </el-card>

    </div>
</template>

<script>
    import moment from "moment";
    import ReplyComponent from "./ReplyComponent";

    export default {
        name: "Comment",
        props: {
            comment: Object,
            forum: Object,
        },
        components: {
            ReplyComponent
        },
        data() {
            return {
                canEdit: Boolean,
                interval: null,
                mode: '',
                form: {
                    comment: '',
                },
            };
        },
        methods: {
            openReply(row) {
                this.dialogReplyVisible = true;
                this.parent = row;
            },
            editComment(item) {
                this.mode = 'Editar';
                this.form = _.cloneDeep(item);
                this.dialogFormVisible = true;
            },
            checkTime() {
                var minutes = moment().diff(moment(this.comment.comment_time), 'minutes');
                if (minutes >= 30) {
                    this.canEdit = false;
                    // here you could also already clear the interval, since it won't change
                } else if (minutes <= 29) {
                    this.canEdit = true;
                }
            }
        },
        created() {
            this.checkTime();
            this.interval = setInterval(() => {
                this.checkTime();
            }, 10000);
        },
        beforeDestroy() {
            clearInterval(this.interval);
        }
    };
</script>
Activity icon

Replied to Having Many Roles, And Permissions How To Check Condition In Nav Bar And Blade Files

What you could do is create a user role table and set the id of the role in the user table as a foreign key, and create a base layout file and set the menu in there and with some ifs you can set the menu for each user role there and since it's in a base layout you only have to do it once. You can have a permissions table and link it to the role id not the user. This is a simple way that it could be done without having to add anything to your project like dependencies.

Jan
21
1 week ago
Activity icon

Replied to Remove Button After 30 Minutes.

@nakov this is that I'm doing exactly that is giving me this error

[Vue warn]: You may have an infinite update loop in a component render function.

<div v-for="comment in forum.comments">
    <el-card shadow="never" v-if="comment.parent_id === null">
        <div style="text-align: end" v-if="comment.user_id === $page.auth.user.auth.user.id">
            {{minutes(comment)}}
            <div v-if="editRemove === false" class="btn-link-edit action-button"
                @click="edit(comment)">
                <i class="fas fa-pencil-alt"></i>
            </div>
        </div>

        <div v-for="reply in comment.replies">
            <div style="text-align: end" v-if="reply.user_id === $page.auth.user.auth.user.id">
                {{minutes(reply)}}
    <div v-if="editRemove === false" class="btn-link-edit action-button"
    @click="edit(reply)">
    <i class="fas fa-pencil-alt"></i>
    </div>
    </div>
    </div>
    </el-card>
</div>
Activity icon

Replied to Remove Button After 30 Minutes.

@nakov the reason the infinite loop was happening was because I was calling the method {{minutes(comment)}} in that loop and then in the reply loop again like this {{minutes(reply)}} but then I get a error that there could be an infinity loop happening. if I do it like this {{minutes(comment)}} in the comment loop it works but when I try to do it also in the reply that's when the problem happens

Activity icon

Replied to Remove Button After 30 Minutes.

@nakov I'm sorry, let me explain the way the view is set up, it's with a couple loops I'll demonstrate with some pseudo-code

 <div v-for="comment in forum.comments">
    //check for other things 
    //set the comment info

    <div v-if="editRemove === false" class="btn-link-edit action-button"
        @click="edit(comment)">
        <i class="fas fa-pencil-alt"></i>
    </div>

    <div v-for="reply in comment.replies">
        //check for other things 
        //set the reply info

        <div v-if="editRemove === false" class="btn-link-edit action-button"
            @click="edit(reply)">
            <i class="fas fa-pencil-alt"></i>
        </div>
    </div>
</div>

So my issue is that I need to check for each comment the user makes and I can't just check the minutes by saying this.comment.comment_time that's why I changed it to theitem.comment_time so I would need to somehow send either the comment or reply the user has made.

This is my issue, if you have another solution (aside from the great help you already gave me) I would love to try it. Thanks

Activity icon

Replied to Remove Button After 30 Minutes.

@nakov How would I pass the item that I need for the function like this?

Activity icon

Replied to Remove Button After 30 Minutes.

@nakov I created this method and it works, what is the best way to call it so it doesn't create an infinite loop

in the data return

editRemove: false,

method

minutes(item) {
    var minutes = moment().diff(moment(item.comment_time), 'minutes');
    if (minutes >= 30) {
        this.editRemove = true;
    } else if (minutes <= 29) {
        this.editRemove = false;
    }
},

in the buttons in the vue.js

<div v-if="editRemove === false" class="btn-link-edit action-button"
    @click="edit(comment)">
    <i class="fas fa-pencil-alt"></i>
</div>
Activity icon

Replied to Remove Button After 30 Minutes.

@nakov where would I put this in the file?

Activity icon

Replied to Remove Button After 30 Minutes.

@nakov could you give me an example?

Activity icon

Started a new Conversation Remove Button After 30 Minutes.

I'm making a discussion forum and I want to remove the users ability to edit the comment they made after 30 mins. Hopefully there is a way to do this so that even when reloading the page the time is not affected.

This is the code for my button in the vue.js, it's not a "real" button, it's a clickable icon

<div class="btn-link-edit action-button"
    @click="edit(comment)">
    <i class="fas fa-pencil-alt"></i>
</div>

method in vue.js

edit(model) {
    this.mode = 'Editar';
    this.form = _.cloneDeep(model);
    this.dialogFormVisible = true;
},

What would be the best way to add this functionality, the timer should start right when the user makes the comment, in the table for this I have a field called comment_time with that information.

How can I do this?

Jan
09
2 weeks ago
Activity icon

Replied to Get Data From Two Tables On Query

@tykus If there are multiple records how would I do the eager loading?

Activity icon

Replied to Get Data From Two Tables On Query

@tykus it's in spanish, calification is the grade

Activity icon

Replied to Get Data From Two Tables On Query

@tykus I would need the grade from that table, sorry id I forgot to mention that

Activity icon

Started a new Conversation Get Data From Two Tables On Query

I'm trying to get like a history of all of the courses a teacher has given that are done and graded. These are the tables I'm trying to search in

    Schema::create('student_schedules', function (Blueprint $table) {
        $table->increments('id');
        $table->date('date')->nullable();
        $table->time('start_time')->nullable();
        $table->time('end_time')->nullable();
        $table->integer('editions')->nullable();
        $table->string('coordinates')->nullable();
        $table->integer('ranking')->nullable();
        $table->unsignedInteger('user_id');
        $table->unsignedInteger('instructor_id')->nullable();
        $table->unsignedInteger('course_id')->nullable();
        $table->unsignedInteger('package_id')->nullable();
        $table->unsignedInteger('location_id')->nullable();
        $table->timestamps();
        // relations
        $table->foreign('user_id')->references('id')
            ->on('users');
        $table->foreign('instructor_id')->references('id')
            ->on('users');
        $table->foreign('course_id')->references('id')
            ->on('courses');
        $table->foreign('package_id')->references('id')
            ->on('packages');
        $table->foreign('location_id')->references('id')
            ->on('locations');
    });

    Schema::create('student_schedules_approveds', function (Blueprint $table) {
        $table->increments('id');
        $table->unsignedInteger('student_schedule_id')->nullable();
        $table->integer('calification')->nullable();
        $table->boolean('approved');
        //relations
        $table->foreign('student_schedule_id')->references('id')
            ->on('student_schedules');
    });

Basically the search I'm trying to do is: select all from student_schedules the first table where the instructor matches the logged in user and where it exists in student_schedules_approveds.

How can I do this?

Jan
08
2 weeks ago
Activity icon

Replied to Delete A User Without Deleting Items The User Has Or Created

@bugsysha How would I deal with the relationships? or does the soft deletes means that I don't have to deal with that?

What about if I want to remove some things but not others?

Activity icon

Started a new Conversation Delete A User Without Deleting Items The User Has Or Created

I want to delete a user but without deleting the things the user had. This system is a school survey system, so if I delete a user there survey answers get deletes, there is a discussion forum and their comments get deleted, if they created something like a question, section or survey that also gets deleted.

Is there a way to delete the user but keep those things?

Activity icon

Started a new Conversation Laravel Menu Active Page

What is the best way to set up the menu so that when I'm in a page the menu displays that menu item as active. Right now the menu item changes color but as soon as the page loads the menu item goes back to normal.

I'm using Element-ui <el-menu> this is the code

<el-menu :gutter="8" :xs="2" :label="true" @open="handleOpen" @close="handleClose"
    :default-active="activeMenu"
    :router="true"
    :collapse="collapse()"
    :unique-opened="true"
    background-color="#1E3260"
    text-color="#BFBFBF"
    active-text-color="#fff">

<inertia-link :href="item.url" v-for="item in menuItems" :key="item.url">
<el-menu-item :index="item.index">
<i :class="item.icon" style="width: 10%"></i>
<span slot="title" style="margin-left: 10%" class="ml-1 layout-name">{{ item.name }}</span>
</el-menu-item>
</inertia-link>
</el-menu>

With this in my data return

activeMenu: null,

in the script

watch: {
    $route (to, from) {
        this.activeMenu = to.path;
    }
},
mounted() {
    this.activeMenu = this.$route.path;
}

This approach isn't working. How can I do this?

Activity icon

Replied to Get Count Of People Who Answered A Question In A Survey

@sti3bas Also important I would need to calculate this variable for each question, or make it dynamic because some questions can be left blank while other cannot so the total number of people answering can change from question to question

Activity icon

Replied to Get Count Of People Who Answered A Question In A Survey

@sti3bas I'm having trouble knowing where exactly to put this in my code, what I have is a foreach for each question then 4 ifs to sort by the question type and inside those another foreach and other ifs in there. This is the code for multiple choice question type. What should be inside the $total variable is 7 but it's returning 1 instead. Where should I put it in this code?

foreach ($survey['surveyQuestions'] as $question) {
    $options = [];

    //if for response_type_id === 1

    if ($question->response_type_id === 2) {
        foreach ($question['surveyQuestionOption'] as $option) {

            if ($question['pivot']->survey_id === $survey->id) {
                $mul_count = 0;
    
                foreach ($survey['answer'] as $answer) {
                    if ($answer->survey_question_id === $option->survey_question_id && (int)$answer->answer === $option->id) {
                    $mul_count++;
                    }

                    $options[$option->id] = [
                        'title' => $option->option,
                        'vote_count' => $mul_count,
                        'total' => $total
                    ];
                }
            }
        }
    }

    //if for response_type_id === 3

    //if for response_type_id === 4

}
Activity icon

Started a new Conversation Get Count Of People Who Answered A Question In A Survey

I'm trying to get the total amount of people who answered a question in a survey, so the survey_id and survey_question_id has to match a value and then I have to be able to separate the user_id so that it counts only the ones that are different, some questions can have multiple answers from the same person. How can I do this?

This is the table schema from the table where I want to get this info

Schema::create('survey_answers', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('survey_id')->unsigned();
            $table->integer('survey_question_id')->unsigned();
            $table->integer('user_id')->unsigned();
            $table->text('answer');
            $table->timestamps();
            $table->foreign('survey_id')->references('id')->on('surveys');
            $table->foreign('survey_question_id')->references('id')->on('survey_questions');
            $table->foreign('user_id')->references('id')->on('users');
        });

I was thinking something like this, this gives me a list of the answers but now how do I separate or count them by the user_id being different?

$total = SurveyAnswer::where('survey_id', $survey->id)->where('survey_question_id', $question->id)->get();
Jan
07
3 weeks ago
Activity icon

Started a new Conversation Installing Barryvdh/laravel-snappy 'cp' Is Not Recognized As An Internal Or External Command

I'm trying to use this dependency (https://github.com/barryvdh/laravel-snappy) but I'm having trouble when it comes to this instruction

Move the binaries to a path that is not in a synced folder, for example:

cp vendor/h4cc/wkhtmltoimage-amd64/bin/wkhtmltoimage-amd64 /usr/local/bin/
cp vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64 /usr/local/bin/

I can't figure out how to do this, if I copy those into the laravel cmd I get this error

'cp' is not recognized as an internal or external command, operable program or batch file.

I tried replacing it with the windows copy and get this error

The syntax of the command is incorrect.

I'm lost as what to do right now with this, if I try and use it without doing this step I get another error and it won't generate the pdf I need.

The exit status code '1' says something went wrong: stderr: "The system cannot find the path specified. " stdout: "" command: /usr/local/bin/wkhtmltopdf --lowquality

What can I do to be able to complete this step?

Jan
06
3 weeks ago
Activity icon

Replied to Show Increasing Number Of Stars Depending On Dynamic Number

@cronix yes, that makes sense, the thing is, that also applies to text questions where that's the answer, or the name of question options, there are 4 different question types (text, multiple choice, ranking and yes or no). So in reality I'm not sure what to name it

Activity icon

Replied to Show Increasing Number Of Stars Depending On Dynamic Number

@cronix yea, the title is set in the controller as the number of stars (1,2,3,4,5 or 6) only, like this

if ($question->rank === 3){
                    $question->opciones = [
                        ['id' => 1, 'option' => 1],
                        ['id' => 2, 'option' => 2],
                        ['id' => 3, 'option' => 3]
                    ];
                } else if ($question->rank === 4){
                    $question->opciones = [
                        ['id' => 1, 'option' => 1],
                        ['id' => 2, 'option' => 2],
                        ['id' => 3, 'option' => 3],
                        ['id' => 4, 'option' => 4]
                    ];
                } else if ($question->rank === 5){
                    $question->opciones = [
                        ['id' => 1, 'option' => 1],
                        ['id' => 2, 'option' => 2],
                        ['id' => 3, 'option' => 3],
                        ['id' => 4, 'option' => 4],
                        ['id' => 5, 'option' => 5]
                    ];
                } else {
                    $question->opciones = [
                        ['id' => 1, 'option' => 1],
                        ['id' => 2, 'option' => 2],
                        ['id' => 3, 'option' => 3],
                        ['id' => 4, 'option' => 4],
                        ['id' => 5, 'option' => 5],
                        ['id' => 6, 'option' => 6]
                    ];
                }

                foreach ($question['opciones'] as $opt) {
                    $count = 0;
                    foreach ($question['answer'] as $answer) {
                        if ($answer->survey_question_id === $question->id && (int)$answer->answer === $opt['option']) {
                            $count++;
                        }

                        $options[$opt['id']] = [
                            'title' => $opt['option'],
                            'vote_count' => $count
                        ];
                    }
                }
Activity icon

Awarded Best Reply on Show Increasing Number Of Stars Depending On Dynamic Number

This was the solution

@if($question['type'] == 3)
     @foreach($question['options'] as $option)
            <table style="width: 100%">
                    <tr>
                            <td style="width: 80%">
                                    for($i = 1; $i <= (int)$option['title']; $i++)
                                        <i class="fas fa-star" style="color: orange"></i>
                                    @endfor
                                </td>
                                <td>
                                    <p class="q_text">{{$option['vote_count']}}</p>
                                </td>
                </tr>
        </table>
    @endforeach
@endif
Activity icon

Replied to Show Increasing Number Of Stars Depending On Dynamic Number

@etiennepeters Thanks I came up with the solution but it's similar to this.

Activity icon

Replied to Show Increasing Number Of Stars Depending On Dynamic Number

This was the solution

@if($question['type'] == 3)
     @foreach($question['options'] as $option)
            <table style="width: 100%">
                    <tr>
                            <td style="width: 80%">
                                    for($i = 1; $i <= (int)$option['title']; $i++)
                                        <i class="fas fa-star" style="color: orange"></i>
                                    @endfor
                                </td>
                                <td>
                                    <p class="q_text">{{$option['vote_count']}}</p>
                                </td>
                </tr>
        </table>
    @endforeach
@endif
Activity icon

Started a new Conversation Show Increasing Number Of Stars Depending On Dynamic Number

I'm trying to make a pdf report where the person can see how many people chose which rating (between 1 - 6) stars and see how many people chose which one. Right now the code I have shows this

1 Amount of people who chose this option: 0
2 Amount of people who chose this option: 0
3 Amount of people who chose this option: 0
4 Amount of people who chose this option: 0
5 Amount of people who chose this option: 0
6 Amount of people who chose this option: 3

However I would like to show the correct amount of stars instead of the number. The tricky part is every ranking can be changed in the sense of the amount of choices there are, so a ranking could be created with 3 stars, 4, 5 or 6. So I would need this to dynamic in that sense.

This is the code I have for showing whats above

@if($question['type'] == 3)
    @foreach($question['options'] as $option)
        <table>
            <tr>
                <td>
                    <p class="q_options">{{$option['title']}}</p>
                </td>
                <td>
                    <p class="q_text">Amount of people who chose this option: </p>
                </td>
                <td>
                    <p class="q_text">{{$option['vote_count']}}</p>
                </td>
            </tr>
        </table>
    @endforeach
@endif

I would like to use this star to replace the number with

<p><span class="fas fa-star" style="color: orange"></span></p>

How can this be done?

Dec
19
1 month ago
Activity icon

Started a new Conversation Getting Only '[object Object]' From Request In Controller?

I don't know what happened, this code was working but I guess I screwed it up while trying to get some other part to work and now this is giving errors. This is the request as shown in the log, I did this Log::info(json_encode($request))

This is the output for the log

local.INFO: array (
  'file' => NULL,
  'name' => 'asf',
  'description' => 'asdf',
  'category' => '6,4,1',
  'steps' => '[object Object]',
  'ingredient' => '[object Object]',
  'measurements' => '[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]',
)  

This is the code for saving in the controller (that now gives me errors in the foreach loop for 'steps')

public function store(Request $request)
    {
        DB::beginTransaction();
        $recipe = new Recipe();
        $recipe->name = $request->name;
        $recipe->description = $request->description;

        $destino = 'img/recipes';
        if ($request->hasFile('file')) {
            $image = $request->file('file');
            $imageName = Uuid::generate(4)->string . '.' . $image->getClientOriginalExtension();
            $recipe->image = '/' . $destino . '/' . $imageName;
            $request->file('file')->move($destino, $imageName);
        }

        $recipe->save();
//        Log::info($request);
        $recipe_id = $recipe->id;

        if ($request->category) {
            foreach (explode(',', str_replace(' ', '', $request->category)) as $c) {
                $recipe->categories()->attach($c);
            }
        }

        $recipe->save();

        if ($request->has('steps')) {
            $steps = [];
            Log::info($request);

            foreach ($request->get('steps') as $number => $item) {
                $num = $number + 1;
                $duration = $item['duration'];
                $instructions = $item['instructions'];

                if (isset($num, $duration, $instructions)) {
                    $steps[] = [
                        "number" => $num,
                        "instructions" => $instructions,
                        "duration" => $duration,
                        "recipe_id" => $recipe_id,
                    ];
                }
                Log::info($steps);
            }
            if (count($steps)) {
                Step::insert($steps);
            }
        }

        if ($request->has('ingredient')) {
            $ingredients = [];

            foreach ($request->get('ingredient') as $item) {
                $ingredient = $item['ingredient'];
                $amount = $item['amount'];
                $measurement = $item['measurement'];

                if (isset($ingredient, $amount, $measurement)) {
                    $ingredients[] = [
                        'recipe_id' => $recipe_id,
                        'ingredient_id' => $ingredient,
                        'amount' => $amount,
                        'measurement_id' => $measurement
                    ];
                }
            }
            if (count($ingredients)) {
                RecipeIngredient::insert($ingredients);
            }
        }
        DB::commit();
        return back();
    }

The specific error I get is

Invalid argument supplied for foreach() on line foreach ($request->get('steps') as $number => $item) {

Why is this happening? How can I fix it?

This is the data from (vue.js)

form: {
    name: '',
    description: '',
image: null,
        imageUrl: '',
},
category: [],
ingredient: [{
    ingredient: '',
        amount: '',
        measurement: ''
}],
steps: [{
    number: '',
    instructions: '',
    duration: '',
img: '',
}],

This is how I'm sending the data

submit() {
    let data = new FormData();
        data.append('file', this.form.image);
        data.append('name', this.form.name);
        data.append('description', this.form.description);
        data.append('category', this.category);
        data.append('steps', this.steps);
        data.append('ingredient', this.ingredient);

        this.$refs.form.validate((valid) => {
        if (valid) {
                    this.loading = true;
                        if (!this.form.id) {
                            this.$inertia.post(this.baseUrl, data).then(
                                () => {
                                    this.recipe = this.$page.recipe;
                                    this.$message({
                                        type: 'success',
                                        message: 'Created correctly.'
                                    });
                                    this.loading = false
                                },
                                (res) => {
                                    this.$message.error(parseError(res)[0]);
                                    this.loading = false;
                                })
                        } else {
                            this.$inertia.post(this.customUpdateUrl + '/' + this.form.id, data).then(
                                () => {
                                    this.recipe = this.$page.recipe;
                                    this.$message({
                                        type: 'success',
                                        message: 'Saved correctly.'
                                    });
                                    this.loading = false
                                },
                                (res) => {
                                    this.$message.error(parseError(res)[0]);
                                    this.loading = false;
                                })
                        }
                } else {
                return false;
                }
        this.reset();
    });
},
Dec
16
1 month ago
Activity icon

Awarded Best Reply on Redirect Showing A Blank Page

the solution was the routes in the wrong order, the full routes should be like this

Route::get('/courses/newcourses', '[email protected]');
Route::get('/courses/{id}/edit', '[email protected]');
Route::post('/courses/{id}', '[email protected]');
Route::resource('courses', 'CourseController');

and i did php artisan route:clear

Activity icon

Replied to Redirect Showing A Blank Page

the solution was the routes in the wrong order, the full routes should be like this

Route::get('/courses/newcourses', '[email protected]');
Route::get('/courses/{id}/edit', '[email protected]');
Route::post('/courses/{id}', '[email protected]');
Route::resource('courses', 'CourseController');

and i did php artisan route:clear

Activity icon

Awarded Best Reply on Only Updating Image If Something Else Is Updated, Not If Only Updating Image

This is the solution someone helped me get to, everything else is correct except for the CourseSaveRequest this is the new code

public function rules()
    {
        $rules = [
            'name' => [
                'required',
                Rule::unique('courses')->ignore($this->id)
            ],
            'summary' => 'required',
            'price' => 'required|numeric|min:0',
            'hours' => 'required|numeric|min:0',
            'min_grade' => 'required|numeric|min:0'
        ];

        return $rules;
    }
Activity icon

Replied to Only Updating Image If Something Else Is Updated, Not If Only Updating Image

This is the solution someone helped me get to, everything else is correct except for the CourseSaveRequest this is the new code

public function rules()
    {
        $rules = [
            'name' => [
                'required',
                Rule::unique('courses')->ignore($this->id)
            ],
            'summary' => 'required',
            'price' => 'required|numeric|min:0',
            'hours' => 'required|numeric|min:0',
            'min_grade' => 'required|numeric|min:0'
        ];

        return $rules;
    }
Activity icon

Replied to Only Updating Image If Something Else Is Updated, Not If Only Updating Image

@talinon this has been solved, I also posted this question on stackoverflow, but yea it was checking that and finding out that the error is in the $rules inside the CourseSaveRequest

Activity icon

Replied to Send Image From Vue To Controller

@edoc yes, I also asked on stackoverflow and that was the answer, now I'm having trouble with another question, could you take a look?

https://laracasts.com/discuss/channels/laravel/only-updating-image-if-something-else-is-updated-not-if-only-updating-image

Activity icon

Started a new Conversation Only Updating Image If Something Else Is Updated, Not If Only Updating Image

I'm trying to update an item that could have an image or change the one that is already there, when I only change the image or add one it doesn't update, but if I change or add an image along with something else like the name or description then it does update both things. I'm not sure why this is happening.

I'm sending it to the controller like this

submit(item) {
    let data = new FormData();
    data.append('file', this.imagen);
    data.append('name', this.ruleForm.name);
    data.append('summary', this.ruleForm.summary);
    data.append('description', this.ruleForm.description);
    data.append('price', this.ruleForm.price);
    data.append('hours', this.ruleForm.hours);
    data.append('min_grade', this.ruleForm.min_grade);
    data.append('matery', this.matery);
    data.append('remover', this.remover);
    data.append('strict', this.strict);

    this.$refs.ruleForm.validate((valid) => {
        if (valid) {
            this.loading = true;
            this.$inertia.post('/courses/' + item.id, data)
                .then(
                    () => {
                        this.$message({
                            type: 'success',
                            message: 'Guardado correctamente.'
                        });
                        this.loading = false
                    },
                    (res) => {
                        this.$message.error(parseError(res)[0]);
                        this.loading = false;
                    })
        } else {
            return false;
        }
    });
},

This is the full update function in the controller

public function update(CourseSaveRequest $request, $id)
{
    Log::info($request);
    $editCourse = Course::find($id);

    $editCourse->name = $request->name;
    $editCourse->summary = $request->summary;
    $editCourse->description = $request->description;
    $editCourse->price = $request->price;
    $editCourse->hours = $request->hours;
    $editCourse->min_grade = $request->min_grade;

    if ($request->hasFile('file')) {
        $this->removeImage($editCourse);
        $image = $request->file('file');
        $imageName = Uuid::generate(4)->string . '.' . $image->getClientOriginalExtension();
        $editCourse->image = '/' . 'img/courses' . '/' . $imageName;
        $request->file('file')->move('img/courses', $imageName);
    }

    $editCourse->save();

    return back();
}

private function removeImage(Course $course){
    if (!empty($course->image) && file_exists(public_path($course->image))) {
        unlink(public_path($course->image));
    }
}

Not sure if this is relevant but this is the CourseSaveRequest

public function rules()
{
    $rules = [
        'name' => 'required|unique:courses',
        'summary' => 'required',
        'price' => 'required|numeric|min:0',
        'hours' => 'required|numeric|min:0',
        'min_grade' => 'required|numeric|min:0'
    ];

    if ($this->has('id')) {
        $rules['name'] .= ',id,'.$this->get('id');
    }

    return $rules;
}

Is there a reason why this is happening and how can I fix it?

Activity icon

Started a new Conversation Redirect Showing A Blank Page

When trying to redirect to /courses/newcourses I get a blank page when it shouldn't be

This is the route

Route::get('/courses/newcourses', '[email protected]');

Function in the controller

$course = Course::all();
return Inertia::render('courses/newcourses', [
    'materia' => $course
]);

The vue.js file it's rendering is full (200+ lines) and exists with the right name and everything (newcourses.vue), there are no errors either when I inspect the page, in fact it's just blank even in the Elements tab there is only 3 things html, head, and body and they're all empty.

What could be causing this problem?

Activity icon

Started a new Conversation Send Image From Vue To Controller

I'm trying to save an image when updating an item but I'm having trouble sending the file to the controller in order to save it. This is how I'm sending it

submit(item) {
    this.$refs.ruleForm.validate((valid) => {
        if (valid) {
            this.loading = true;
            this.$inertia.post('/courses/' + item.id, {
                name: this.ruleForm.name,
                summary: this.ruleForm.summary,
                description: this.ruleForm.description,
                price: this.ruleForm.price,
                hours: this.ruleForm.hours,
                min_grade: this.ruleForm.min_grade,
                file: this.imagen,
                matery: this.matery,
                remover: this.remover,
                strict: this.strict
            }).then(
                () => {
                    this.$message({
                        type: 'success',
                        message: 'Guardado correctamente.'
                    });
                    this.loading = false
                },
                (res) => {
                    this.$message.error(parseError(res)[0]);
                    this.loading = false;
                })
        } else {
            return false;
        }
    });
},

If I {{imagen}} and {{imageUrl}} in the vue this is the result respectively, this is why I'm sending the imagen and not the url

[object File] 

blob:http://dev.inae.com/9c77fa72-b778-45c9-8ab2-0a9084282415

When I Log::info($request) this is the output, when adding a file and changing text and saving,

local.INFO: array (
  'name' => 'Principiante Clase 3 (automático)',
  'summary' => 'Enseñaremos a compresionar el vehículo y la utilización de 
                cambios en vehículo automático',
  'description' => '<p>Enseñaremos a compresionar el vehículo y la utilización de 
                cambios en vehículo automático (viaje a fraijanes).</p>',
  'price' => 52000,
  'hours' => 2,
  'min_grade' => 70,
  'file' => 
  array (
    'uid' => 1576507762527,
  ),
  'matery' => NULL,
  'remover' => false,
  'strict' => false,
)  

However if I only add the image and don't change anything else, nothing happens in the Log

Code for updating the image in the controller, in the update function

//Log is here
$editCourse = Course::find($id);
$destino = "img/courses";
$link = public_path();

if ($request->hasFile('file')) {
    if (!empty($editCourse->image) && file_exists($link . $editCourse->image)) {
        unlink($link . $editCourse->image);
    }
    $image = $request->file('file');
    $imageName = Uuid::generate(4)->string . '.' . $image->getClientOriginalExtension();
    $editCourse->image = '/' . $destino . '/' . $imageName;
    $request->file('file')->move($destino, $imageName);
}

What could I be doing wrong?

Dec
11
1 month ago
Activity icon

Started a new Conversation Classify Question Answers By Option And Count How Many People Answered A Question With Said Option

This is the data from the database I'm trying to classify and categorize, I put one question with the answers for each type, text, yes or no, multiple choice, ranking.

{ 
   "id":1,
   "name":"Evaluacion al docente por parte de los estudiantes",
   "description":"Evaluacion al docente de la clase de Electronica 1 de la carrera de Ingenieria",
   "user_id":1,
   "anonymous":0,
   "created_at":"2019-12-09 10:30:50",
   "updated_at":"2019-12-10 08:43:40",
   "survey_questions":[ 
      { 
         "id":1,
         "question":"Cual es su opinion acerca de la oficina de telematica",
         "user_id":1,
         "survey_section_id":1,
         "response_type_id":1,
         "optional":0,
         "num":null,
         "rank":null,
         "show_text":0,
         "created_at":"2019-12-09 10:29:27",
         "updated_at":"2019-12-10 08:20:50",
         "pivot":{  },
         "response_type":{ 
            "id":1,
            "type":"Texto"
         },
         "survey_question_option":[ 

         ],
         "answer":[ 
            { 
               "id":1,
               "survey_id":1,
               "survey_question_id":1,
               "user_id":2,
               "answer":"muy bien",
               "created_at":"2019-12-10 08:25:12",
               "updated_at":"2019-12-10 08:25:12"
            },
            { 
               "id":7,
               "survey_id":1,
               "survey_question_id":1,
               "user_id":3,
               "answer":"fd asdf asdfasddsaf",
               "created_at":"2019-12-10 08:25:59",
               "updated_at":"2019-12-10 08:25:59"
            },
            { 
               "id":13,
               "survey_id":1,
               "survey_question_id":1,
               "user_id":4,
               "answer":"lkklj i klike lakd aoiadlkj askfj askfjoaweij alkd aksdf asd",
               "created_at":"2019-12-10 08:28:17",
               "updated_at":"2019-12-10 08:28:17"
            },
            { 
               "id":19,
               "survey_id":1,
               "survey_question_id":1,
               "user_id":5,
               "answer":"l kdf jalskdf jalsdf afdsf afd ds lkdsjflak jaf",
               "created_at":"2019-12-10 08:28:51",
               "updated_at":"2019-12-10 08:28:51"
            }
         ]
      },
      { 
         "id":2,
         "question":"elija 3 opciones",
         "user_id":1,
         "survey_section_id":1,
         "response_type_id":2,
         "optional":0,
         "num":3,
         "rank":null,
         "show_text":0,
         "created_at":"2019-12-10 08:21:21",
         "updated_at":"2019-12-10 08:21:21",
         "pivot":{ 
            "survey_id":1,
            "survey_question_id":2
         },
         "response_type":{ 
            "id":2,
            "type":"Selecci\u00f3n M\u00faltiple"
         },
         "survey_question_option":[ 
            { 
               "id":1,
               "option":"opcion a",
               "survey_question_id":2,
               "created_at":null,
               "updated_at":null
            },
            { 
               "id":2,
               "option":"opcion b",
               "survey_question_id":2,
               "created_at":null,
               "updated_at":null
            },
            { 
               "id":3,
               "option":"opcion c",
               "survey_question_id":2,
               "created_at":null,
               "updated_at":null
            },
            { 
               "id":4,
               "option":"opcion d",
               "survey_question_id":2,
               "created_at":null,
               "updated_at":null
            }
         ],
         "answer":[ 
            { 
               "id":2,
               "survey_id":1,
               "survey_question_id":2,
               "user_id":2,
               "answer":"1",
               "created_at":"2019-12-10 08:25:12",
               "updated_at":"2019-12-10 08:25:12"
            },
            { 
               "id":8,
               "survey_id":1,
               "survey_question_id":2,
               "user_id":3,
               "answer":"3",
               "created_at":"2019-12-10 08:25:59",
               "updated_at":"2019-12-10 08:25:59"
            },
            { 
               "id":14,
               "survey_id":1,
               "survey_question_id":2,
               "user_id":4,
               "answer":"4",
               "created_at":"2019-12-10 08:28:17",
               "updated_at":"2019-12-10 08:28:17"
            },
            { 
               "id":20,
               "survey_id":1,
               "survey_question_id":2,
               "user_id":5,
               "answer":"4",
               "created_at":"2019-12-10 08:28:51",
               "updated_at":"2019-12-10 08:28:51"
            }
         ]
      },
      { 
         "id":3,
         "question":"bota la basura en los basureros?",
         "user_id":1,
         "survey_section_id":2,
         "response_type_id":4,
         "optional":1,
         "num":null,
         "rank":null,
         "show_text":0,
         "created_at":"2019-12-10 08:21:52",
         "updated_at":"2019-12-10 08:21:52",
         "pivot":{  },
         "response_type":{ 
            "id":4,
            "type":"Si o No"
         },
         "survey_question_option":[ 

         ],
         "answer":[ 
            { 
               "id":4,
               "survey_id":1,
               "survey_question_id":3,
               "user_id":2,
               "answer":"No",
               "created_at":"2019-12-10 08:25:12",
               "updated_at":"2019-12-10 08:25:12"
            },
            { 
               "id":10,
               "survey_id":1,
               "survey_question_id":3,
               "user_id":3,
               "answer":"Si",
               "created_at":"2019-12-10 08:25:59",
               "updated_at":"2019-12-10 08:25:59"
            },
            { 
               "id":16,
               "survey_id":1,
               "survey_question_id":3,
               "user_id":4,
               "answer":"No",
               "created_at":"2019-12-10 08:28:17",
               "updated_at":"2019-12-10 08:28:17"
            }
         ]
      },
      { 
         "id":4,
         "question":"Que calificacion le daria a la limpieza general de la universidad?",
         "user_id":1,
         "survey_section_id":2,
         "response_type_id":3,
         "optional":0,
         "num":null,
         "rank":6,
         "show_text":1,
         "created_at":"2019-12-10 08:22:37",
         "updated_at":"2019-12-10 08:22:37",
         "pivot":{  },
         "response_type":{ 
            "id":3,
            "type":"Rango"
         },
         "survey_question_option":[ 

         ],
         "answer":[ 
            { 
               "id":5,
               "survey_id":1,
               "survey_question_id":4,
               "user_id":2,
               "answer":"6",
               "created_at":"2019-12-10 08:25:12",
               "updated_at":"2019-12-10 08:25:12"
            },
            { 
               "id":11,
               "survey_id":1,
               "survey_question_id":4,
               "user_id":3,
               "answer":"6",
               "created_at":"2019-12-10 08:25:59",
               "updated_at":"2019-12-10 08:25:59"
            },
            { 
               "id":17,
               "survey_id":1,
               "survey_question_id":4,
               "user_id":4,
               "answer":"6",
               "created_at":"2019-12-10 08:28:17",
               "updated_at":"2019-12-10 08:28:17"
            }
         ]
      },
   ]
}

This is the code so far however I'm having trouble

$survey = Survey::with( 'surveyQuestions.responseType','surveyQuestions.surveyQuestionOption', 'surveyQuestions.answer')
            ->where('id', $id)->first();

    $result = [];

    foreach ($survey['surveyQuestions'] as $question) {
        $options = [];

        if (!in_array($question->response_type_id, [2, 3, 4])) {
            continue;
        }

        foreach ($question['surveyQuestionOption'] as $option) {
            $count = 0;
            foreach ($survey['answer'] as $answer) {
                // output 1 :dd(json_encode($answer));
                if ($answer->survey_question_id === $option->survey_question_id) {
                    $count++;
                }
            }
        }

        $options[$option->id] = [
            'title' => $option->option,
            'vote_count' => $count
        ];
        // output 2: dd(json_encode($options));
    }

    $result[$question->id] = [
      'title' => $question->question,
      'options' => $options
    ];
    // output 3: dd(json_encode($result));
}

outputs

1:
"{"id":1,"survey_id":1,"survey_question_id":1,"user_id":2,"answer":"muy bien","created_at":"2019-12-10 08:25:12","updated_at":"2019-12-10 08:25:12"}"

2:
"{"4":{"title":"opcion d","vote_count":4}}"

3:
{"6":{"title":"jaksjakjf fjf a jaskj fkf ja range","options":{"4":{"title":"opcion d","vote_count":4}}}}"

The issue is that only one type of question has the 'surveyQuestionOptions' which is the multiple choice. Also the output are wrong, the output 1 shows the wrong answer, it shows the first answer for the question type: text with response_type_id === 1. I thought this code skipped over that type, if not I would like to fix this to save the text answers and move on.

if (!in_array($question->response_type_id, [2, 3, 4])) {
    continue;
}

I was also under the impression that the $options array output would show all options and it only shows the last one there are 4 options in total, same with the result, I thought it would show an array with all the questions and the options array that belongs to it as well and it's showing something totally off. that question it's showing is a ranking question and doesn't even have options the answer for a rank question is a number between 1 - 6.

I would like to be able to save the questions something like this

TEXT
question 
//all answers 

YES OR NO
question
yes x amount of people 
no x amount of people

RANKING (depending on stars set by question, could be between 3 - 6)
question 
1 star x amount of people 
2 star x amount of people 
3 star x amount of people 

MULTIPLE CHOICE (could be one entry in the db or more depending on the amount of options that can be selected)
question
option 1 x amount of people  
option 2 x amount of people 
option 3 x amount of people 
option 4 x amount of people 

the x amount of people is just a count of how many answers match (excluding the text question) or belong to a certain option for the multiple choice.

There should be max 4 answers per question, some questions are optional so the person doesn't have to answer it but for the most part there should be 4 answers.

I'm not sure how to get the code I have working properly to classify and save these questions and answers the right way?

Dec
10
1 month ago
Activity icon

Replied to Count A Variable Inside An Array To Display How Many Answers Match.

@bugsysha it doesn't really matter to me where as long as I can do it, could be in the controller where I'm sending the data

Activity icon

Started a new Conversation Count A Variable Inside An Array To Display How Many Answers Match.

I'm making a report where the user is shown a summary of the results of a survey. There are 4 types of questions: text, yes or no, multiple choice, and ranking. for each question except text I would like to say x amount of people selected this option, or something like that.

This is the blade

@foreach($survey['surveyQuestions'] as $question)
    <div>
        <p>question: {{$question}}</p>
        <p class="q_name">{{$question->question}}</p>

        @if($question->response_type_id == 2)
            <p>Seleccion Multiple</p>
            <p>Opciones</p>
            @foreach($question['surveyQuestionOption'] as $option)
                <p>{{$option->option}}</p>
            @endforeach

            @foreach($survey['answer'] as $answer)
                @if($answer->survey_question_id == $question->id)
                    {{$answer}}
                @endif
            @endforeach
        @endif
        @if($question->response_type_id == 3)
            <p>Rango</p>
            @foreach($survey['answer'] as $answer)
                @if($answer->survey_question_id == $question->id)
                    <p>{{$answer}}</p>
                @endif
            @endforeach
        @endif
        @if($question->response_type_id == 4)
            <p>Si o No</p>
            @foreach($survey['answer'] as $answer)
                @if($answer->survey_question_id == $question->id)
                    <p>{{$answer}}</p>
                @endif
            @endforeach
        @endif
    </div>
@endforeach

The current output is for multiple choice is

@if($question->response_type_id == 2)
    <p>Seleccion Multiple</p>
    <p>Opciones</p>
    @foreach($question['surveyQuestionOption'] as $option)
        <p>{{$option->option}}</p>
    @endforeach

    @foreach($survey['answer'] as $answer)
        @if($answer->survey_question_id == $question->id)
            {{$answer}}
        @endif
    @endforeach
@endif

is

elija 3 opciones
Seleccion Multiple
Opciones
opcion a
opcion b
opcion c
opcion d
{"id":2,"survey_id":1,"survey_question_id":2,"user_id":2,"answer":"1","created_at":"2019-12-10
08:25:12","updated_at":"2019-12-10 08:25:12"}
{"id":8,"survey_id":1,"survey_question_id":2,"user_id":3,"answer":"3","created_at":"2019-12-10
08:25:59","updated_at":"2019-12-10 08:25:59"}
{"id":14,"survey_id":1,"survey_question_id":2,"user_id":4,"answer":"4","created_at":"2019-12-10
08:28:17","updated_at":"2019-12-10 08:28:17"}
{"id":20,"survey_id":1,"survey_question_id":2,"user_id":5,"answer":"4","created_at":"2019-12-10
08:28:51","updated_at":"2019-12-10 08:28:51"}

output for rank questions

@if($question->response_type_id == 3)
    <p>Rango</p>
    @foreach($survey['answer'] as $answer)
        @if($answer->survey_question_id == $question->id)
            <p>{{$answer}}</p>
        @endif
    @endforeach
@endif

is

jaksjakjf fjf a jaskj fkf ja range
Rango
{"id":6,"survey_id":1,"survey_question_id":6,"user_id":2,"answer":"3","created_at":"2019-12-10
08:25:12","updated_at":"2019-12-10 08:25:12"}
{"id":12,"survey_id":1,"survey_question_id":6,"user_id":3,"answer":"3","created_at":"2019-12-10
08:25:59","updated_at":"2019-12-10 08:25:59"}
{"id":18,"survey_id":1,"survey_question_id":6,"user_id":4,"answer":"3","created_at":"2019-12-10
08:28:17","updated_at":"2019-12-10 08:28:17"}

output for yes or no is

@if($question->response_type_id == 4)
    <p>Si o No</p>
    @foreach($survey['answer'] as $answer)
        @if($answer->survey_question_id == $question->id)
            <p>{{$answer}}</p>
        @endif
    @endforeach
@endif

is

bota la basura en los basureros?
Si o No
{"id":4,"survey_id":1,"survey_question_id":3,"user_id":2,"answer":"No","created_at":"2019-12-10
08:25:12","updated_at":"2019-12-10 08:25:12"}
{"id":10,"survey_id":1,"survey_question_id":3,"user_id":3,"answer":"Si","created_at":"2019-12-10
08:25:59","updated_at":"2019-12-10 08:25:59"}
{"id":16,"survey_id":1,"survey_question_id":3,"user_id":4,"answer":"No","created_at":"2019-12-10
08:28:17","updated_at":"2019-12-10 08:28:17"}

My question is, Is there a way to count the answers that are the same and show those results next to the option something like this.

Yes or No question.
Do you like to eat bread?
yes -> 4 people answered or %67 
no -> 2 people answered or %33
Dec
05
1 month ago
Activity icon

Replied to 401 Unauthorized While Trying To Load Page

@nakov it doesn't matter if I put passport or session in the auth.php I still get the same error

Activity icon

Replied to 401 Unauthorized While Trying To Load Page

@nakov I've never user passport before, how should I add the token? The Users table doesn't have a token per say but it does have a uuid field, I'm assuming it's used for this purpose.

Activity icon

Replied to 401 Unauthorized While Trying To Load Page

@nakov

'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'passport',
            'provider' => 'users',
        ],
    ],
Activity icon

Replied to 401 Unauthorized While Trying To Load Page

@nakov there isn't much in the RouteServiceProvider but I'll post what is there

 protected $namespace = 'App\Http\Controllers';

public function boot()
    {
        //

        parent::boot();
    }

public function map()
    {
        $this->mapApiRoutes();

        $this->mapWebRoutes();

        //
    }

protected function mapWebRoutes()
    {
        Route::middleware('web')
             ->namespace($this->namespace)
             ->group(base_path('routes/web.php'));
    }

protected function mapApiRoutes()
    {
        Route::prefix('api')
             ->middleware('api')
             ->namespace($this->namespace)
             ->group(base_path('routes/api.php'));
    }
Activity icon

Replied to 401 Unauthorized While Trying To Load Page

@nakov its local only, I don't have to pay for it since that's just the name I give it on my computer, that's not a real website address. That's why I use dev. before to differentiate the projects currently in development. I have others that are page.me or stuff like that, it's just a name.