msslgomez

Member Since 1 Year Ago

Experience Points
21,370
Total
Experience

3,630 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
7
Lessons
Completed
Best Reply Awards
5
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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.

  • Community Pillar

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

Level 5
21,370 XP
Apr
29
2 weeks ago
Activity icon

Awarded Best Reply on Props Not Being Passed From Parent To Child

I don't know what it was but it's working now

Activity icon

Replied to Props Not Being Passed From Parent To Child

I don't know what it was but it's working now

Activity icon

Replied to Props Not Being Passed From Parent To Child

I had also tried it this way without any success

Activity icon

Started a new Conversation Props Not Being Passed From Parent To Child

I have a layout component that gets called on every page. I want to send a prop to the layout from the other component where it's being called but so far nothing is being passed.

This is the layout component code

<template>
    <div>

        <b-navbar>
            <b-navbar-nav>
                <span v-for="(perm, index) in perms" :key="index">
                    <b-nav-item :class="getNavClass(perm, index)">
                        <inertia-link class="nav-link" style="padding: 0" :href="perm.url">{{
                                getNavClass(perm, index)
                            }}</inertia-link>
                    </b-nav-item>
                </span>
            </b-navbar-nav>
        </b-navbar>

        <b-container>
            <p>menu-name = {{ menuName }}</p>
            <slot></slot>
        </b-container>

    </div>
</template>
<script>
export default {

    name: 'layout',
    data() {
        return 
            perms: []
        }
    },
    props: {
        menuName: {
            required: true,
            type: String,
            default: ''
        },
    },
    methods: {
        getNavClass(perm, index) {
            if (perm.name === this.perms[index] && this.menuName === perm.name){
                return 'active:' + this.menuName.toLowerCase();
            }
            return false;
        },
    },
}

</script>

This is the component where the layout is being called

<template>
    <layout v-bind:menu-name="this.menuItem">
        <h1>Users</h1>

        {{users}}

    </layout>
</template>
<script>
import Layout from "../Layout";

export default {
    components: {
        Layout
    },
    data() {
        return {
            users: [],
            menuItem: 'Users'
        }
    },
}
</script>

I've tried a bunch or different ways but nothing has worked:

v-bind:menu-name="this.menuItem"
:menu-name="menuItem"
menu-item="Users"
:menu-item="'Users'"

I'm not sure what I'm doing wrong? How can I fix it?

Apr
28
2 weeks ago
Activity icon

Started a new Conversation Bootstrap-Vue NavBar Display Nav-item As Active

I'm trying to show the active nav item but so far they all show as active instead of only one. I'm using Inertia.js in case that's important.

I'm getting a list of menu items that look like this

$perms = [
    [
         'url' => '/',
         'icon' => 'fa fa-home',
         'name' => 'Home',
    ],
    [
         'url' => '/users',
         'icon' => 'fa fa-home',
         'name' => 'Users',
    ],
];

This is the menu in a LayoutComponent, in the docs https://bootstrap-vue.org/docs/components/navbar#comp-ref-b-navbar-brand-props

They have a prop called active but it's a Boolean so I'm not sure how I can differentiate between the menu items.

<b-navbar style="background-color: #4392F1" type="light">
    <b-navbar-nav justified>
        <b-nav-item :active="activeMenu" v-for="(perm, index) in perms" :key="index">
            <inertia-link class="nav-link" style="padding: 0" :href="perm.url">{{ perm.name }}</inertia-link>
        </b-nav-item>
    </b-navbar-nav>
</b-navbar>


//script
props: {
        activeMenu: {
            type: Boolean,
            default: false
        },
    },

And in the other components I use it like this, but again now all the menu items are set as active.

<template>
    <layout :active-menu="true">

    </layout>
</template>

How can I fix this to only affect the current menu item?

Apr
16
1 month ago
Activity icon

Replied to Get Jobs To Run Without Installing Supervisor

Well, I don't know how to set it up, I tried twice and got errors both times and honestly I'm terrified of working on the company server the most I want to do there is a git pull origin master.

So I wanted a way to do this with code, I know there is a way to run php artisan commands using code so maybe I can do it that way at least temporarily.

Activity icon

Awarded Best Reply on Dynamically Create A Folder In A Public Storage Disk

sorry for the confusion, the tinker command didn't work. But yea the filesystems.php looks like this

'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

        'report_upload' => [
            'driver' => 'local',
            'root' => public_path('reports'),
        ],

        's3' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
        ],

    ],

I have it working as I want with the following code

        $request_date = date_create(JobRequest::find($this->request_id)->request_time);

        $path = public_path('reports/reports_' . date_format($request_date, 'd_m_Y'));
        if (!File::exists($path)) {
            File::makeDirectory($path, 0755, true);
        }

        Excel::store(new SurveyReport($items), $name . '.xlsx', 'report_upload');

        if (Storage::disk('report_upload')->exists($name . '.xlsx')) {
            rename(public_path('reports/' . $name . '.xlsx'),
                public_path('reports/reports_' . date_format($request_date, 'd_m_Y') . '/' . $name . '.xlsx'));
        }

Thank you for all your help.

Activity icon

Replied to Dynamically Create A Folder In A Public Storage Disk

sorry for the confusion, the tinker command didn't work. But yea the filesystems.php looks like this

'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

        'report_upload' => [
            'driver' => 'local',
            'root' => public_path('reports'),
        ],

        's3' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
        ],

    ],

I have it working as I want with the following code

        $request_date = date_create(JobRequest::find($this->request_id)->request_time);

        $path = public_path('reports/reports_' . date_format($request_date, 'd_m_Y'));
        if (!File::exists($path)) {
            File::makeDirectory($path, 0755, true);
        }

        Excel::store(new SurveyReport($items), $name . '.xlsx', 'report_upload');

        if (Storage::disk('report_upload')->exists($name . '.xlsx')) {
            rename(public_path('reports/' . $name . '.xlsx'),
                public_path('reports/reports_' . date_format($request_date, 'd_m_Y') . '/' . $name . '.xlsx'));
        }

Thank you for all your help.

Activity icon

Replied to Dynamically Create A Folder In A Public Storage Disk

I think either at this point I'm retarded or this is harder that it should be (I'm probably just overthinking it), I decided to create the Excel file using the disk. Then move it to the folder, but I can't figure it out, nothing is working.

Excel::store(new SurveyReport($items), $name . '.xlsx', 'report_upload');

if (Storage::disk('report_upload')->exists($name . '.xlsx')) {

// I've tried this
    Storage::disk('report_upload')->move(Storage::get($name . '.xlsx'),
            'reports/reports_' . date_format($request_date, 'd_m_Y') . '/' . $name . '.xlsx');

    Storage::move(Storage::get($name . '.xlsx'),
            'reports/reports_' . date_format($request_date, 'd_m_Y') . '/' . $name . '.xlsx');

    Storage::move(Storage::get('reports/' . $name . '.xlsx'),
            'reports/reports_' . date_format($request_date, 'd_m_Y') . '/' . $name . '.xlsx');
 }

The files are in on my local computer

C:\xampp\htdocs\unadeca\public\reports

Every way I've tried returns

File not found at path

Activity icon

Replied to Dynamically Create A Folder In A Public Storage Disk

@snapey I can create the directory like this

        $path = public_path('report_upload/reports_' . date_format($request_date, 'd_m_Y'));
        $ex_path = 'report_upload/reports_' . date_format($request_date, 'd_m_Y');
        if (!File::exists($path)) {
           File::makeDirectory($path, 0755, true);
        }

        Excel::store(new SurveyReport($items), $name . '.xlsx', $ex_path);

And this works the folder gets created but the Excel file gives the error about the disk not having a configured driver.

Is there a way to create it and save it to a path itself instead of a Storage disk?

Activity icon

Replied to Dynamically Create A Folder In A Public Storage Disk

Still the same error: Disk does not have a configured driver

Activity icon

Replied to Dynamically Create A Folder In A Public Storage Disk

I changed it to report_upload/reports_16_04_2021 and still nothing happens

Activity icon

Replied to Dynamically Create A Folder In A Public Storage Disk

What can I replace it with? Which characters are permitted? I'm ok with keeping only the date

Activity icon

Replied to Dynamically Create A Folder In A Public Storage Disk

ok, now I don't failed jobs BUT also nothing happens, no folder and no Excel files anywhere

Activity icon

Started a new Conversation Dynamically Create A Folder In A Public Storage Disk

I'm trying to create a new folder inside a public disk but I'm having issues. This is what I have so far

 while (Storage::disk('report_upload')->exists($name . '.xlsx')) {
            $name .= $counter;
            $counter++;

            Storage::disk('report_upload')->makeDirectory('Reportes-' . $request->request_time);
        }

        Excel::store(new SurveyReport($items), $name . '.xlsx', 
            'report_upload/Reportes-' . $request->request_time);

This is for a Job but they all fail with this error

InvalidArgumentException: Disk [report_upload/Reportes-2021-04-16 13:13:45] does not have a configured driver.

This is my config filesystems.php

  'report_upload' => [
            'driver' => 'local',
            'root' => public_path() . '/reports',
        ],

What am I doing wrong?

Also side question, this is to download all the files that get created, should I just take everything to a zip file regardless of what gets created and then delete everything? I wanted to create a folder for each time these files have to get created but that's where I'm stuck.

A folder does get created but not by me for the same file every time and I don't know what's up with that.

Activity icon

Started a new Conversation Installing Supervisor On Centos Server

I hate doing stuff on the company server, I'm trying to setup some jobs and run the queue and from what I read I need Supervisor but I have no idea how to actually set it up.

I'm ssh into the server and am in this folder /public_html/project and I tried this command sudo apt-get install supervisor like it says in the docs but then I get this error

sudo: effective uid is not 0, is /usr/bin/sudo on a file system with the 'nosuid' option set or an NFS file system without root privileges?

Now what? Am I trying to install this in the wrong place? I'm at a loss

Activity icon

Started a new Conversation Get Jobs To Run Without Installing Supervisor

I have some Jobs that create files but after dispatching the jobs, the entries are saved to the db but then they don't run or execute without a php artisan queue:work manual command.

The idea for this is to set it on a server and me not having to run a command or do anything manual every time these Jobs get dispatched which honestly is not that frequent, maybe once or twice in a 3 month period.

How can get these jobs to execute without having to run a command each time? Could I make a method or something with code instead?

Apr
15
1 month ago
Activity icon

Started a new Conversation Create And Download Multiple Excel Files To A Zip

I have a bunch of reports that the user can download, the thing is I first need to create the Excels and then download a Zip. This worked locally but now on the server I'm having a lot of issues.

First I create the list of reports and then dispatch a Job for each, this Job should create the Excel file but it doesn't actually create it but I also don't get any errors. This is the code to create the actual file

$items = Survey::findOrFail($this->report->survey_id);

$name = str_replace(':', '', $items->name);
$counter = 1;

while (Storage::disk('report_upload')->exists($name . '.xlsx')) {
        $name .= $counter;
        $counter++;
}

Excel::store(new SurveyReport($items), $name . '.xlsx', 'report_upload');

if (Storage::disk('report_upload')->exists($name . '.xlsx')){
        $job_request_report = JobRequestReport::where('survey_id', $this->report->survey_id)
        ->where('request_id', $this->request_id)->first();

        if ($job_request_report) {
                $job_request_report->report_name = $name;
                $job_request_report->processed = true;
                $job_request_report->save();
        }
}

The Excel gets created using a Blade View

Then another job is dispatched that checks if it's finished

$reports = JobRequestReport::where('request_id', $this->id)
            ->where('processed', false)->count();

        if ($reports == 0) {
            $job_request = JobRequest::findOrFail($this->id);
            $job_request->completed = true;
            $job_request->save();

            $user = User::findOrFail(JobRequest::findOrFail($this->id)->user_id);
            $user->notify(new QueueDone($job_request->id,
                'Download is ready. Click here to download.'));
        } else {
            $job_request = JobRequest::findOrFail($this->id);
            $job_request->completed = true;
            $job_request->save();

            $job_reports = JobRequestReport::where('request_id', $job_request->id)->where('processed', false)->get();

            $user = User::findOrFail(JobRequest::findOrFail($this->id)->user_id);

            if (count($job_reports) > 1) {
                $user->notify(new QueueDone($job_request->id,
                    'Download is ready. Error in ' . count($job_reports) . ' files. Click here to download.'));
            } else {
                $user->notify(new QueueDone($job_request->id,
                    'Download is ready. Error in ' . count($job_reports) . ' file. Click here to download.'));
            }
        }

Then the user gets a notification where they get the message and can click to download. But when they try it says File Not Found.

This is the method for downloading the Zip

$job_request = JobRequest::findOrFail($request->request_id);
        if ($job_request->user_id == auth()->user()->id) {
            $zip = new ZipArchive;

            if (true === ($zip->open('ReportesTodos-' . $request->request_id . '.zip',
                    ZipArchive::CREATE | ZipArchive::OVERWRITE))) {

                foreach ($job_request->reports as $report) {
                    if (Storage::disk('report_upload')->exists($report->report_name . '.xlsx')) {
                        $zip->addFile(public_path('reports\' . $report->report_name . '.xlsx'),
                            $report->report_name . '.xlsx');
                    }
                }
                $zip->close();
            }

            $user = auth()->user();
            foreach ($user->notifications as $notification) {
                if ($notification->id == $request->notification_id) {
                    $notification->markAsRead();
                }
            }
        }
        return response()->download(public_path('ReportesTodos-' . $request->request_id . '.zip'),
            'ReportesTodos-' . $request->request_id . '.zip');

What am I doing wrong?

Activity icon

Replied to Creating Default Object From Empty Value

I added a comment to the code it's on this line

$items->totalSent = $tot;

And I'm getting $tot like this, the reason behind this if is that the evaluators can be saved either in a group id or by user ids

        if ($evaluators[0]->user_id == null) {
            $tot = $evaluators[0]['group']['users']->count();
        } else {
            $tot = $evaluators->count();
        }
Activity icon

Replied to Creating Default Object From Empty Value

The weird this is if I do dd($tot, $totalAnswered); I can see the values correctly but if I remove the dd I get a 500 error.

Activity icon

Started a new Conversation Creating Default Object From Empty Value

I'm not sure what is going on but I keep getting the error in the title in this code

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

        $Eid = Evaluation::where('survey_id', $this->report->survey_id)->pluck('id')->first();
        $evaluators = EvaluationEvaluator::where('evaluation_id', $Eid)->with('group.users')->get();

        if ($evaluators[0]->user_id == null) {
            $tot = $evaluators[0]['group']['users']->count();
        } else {
            $tot = $evaluators->count();
        }

        $totalAnswered = SurveyAnswer::where('survey_id', $survey->id)->selectRaw('COUNT(DISTINCT user_id) as count')
            ->value('count');

        $result = [];

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

            if ($question->response_type_id === 1) {
                foreach ($survey['answer'] as $answer) {
                    if ($question['pivot']->survey_id === $survey->id) {
                        if ($answer->survey_question_id === $question->id) {
                            $options[$answer->id] = [
                                'title' => $answer->answer,
                                'vote_count' => null
                            ];
                        }
                    }
                }
            }

            if ($question->response_type_id === 2) {
                $mul_total = SurveyAnswer::where('survey_id', $survey->id)->where('survey_question_id', $question->id)
                    ->selectRaw('COUNT(DISTINCT user_id) as count')
                    ->value('count');

                foreach ($question['surveyQuestionOption'] as $option) {
                    if ($question['pivot']->survey_id === $survey->id) {
                        $mul_users = [];

                        foreach ($survey['answer'] as $answer) {
                            if ($answer->survey_question_id === $option->survey_question_id
                                && (int)$answer->answer === $option->id) {
                                $mul_count[] = $answer->user_id;
                            }

                            $options[$option->id] = [
                                'title' => $option->option,
                                'vote_count' => count(array_unique($mul_users)),
                                'total' => $mul_total,
                                'users' => array_unique($mul_users)
                            ];
                        }
                    }
                }
            }

            if ($question->response_type_id === 3) {
                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]
                    ];
                }

                $rk_total = SurveyAnswer::where('survey_id', $survey->id)->where('survey_question_id', $question->id)
                    ->selectRaw('COUNT(DISTINCT user_id) as count')
                    ->value('count');

                foreach ($question['opciones'] as $opt) {
                    $rk_users = [];

                    foreach ($question['answer'] as $answer) {
                        if ($answer->survey_id === $survey->id) {
                            if ($answer->survey_question_id === $question->id && (int)$answer->answer === $opt['option']) {
                                $rk_users[] = $answer->user_id;
                            }

                            $options[$opt['id']] = [
                                'title' => $opt['option'],
                                'vote_count' => count(array_unique($rk_users)),
                                'total' => $rk_total,
                                'users' => array_unique($rk_users)
                            ];
                        }
                    }
                }
            }

            if ($question->response_type_id === 4) {
                $question->opciones = [
                    ['id' => 1, 'option' => 'Si'],
                    ['id' => 2, 'option' => 'No']
                ];

                $total = SurveyAnswer::where('survey_id', $survey->id)->where('survey_question_id', $question->id)
                    ->selectRaw('COUNT(DISTINCT user_id) as count')
                    ->value('count');

                foreach ($question['opciones'] as $opt) {
                    $yn_users = [];

                    foreach ($question['answer'] as $answer) {
                        if ($answer->survey_id === $survey->id) {
                            if ($answer->survey_question_id === $question->id && $answer->answer === $opt['option']) {
                                $yn_users[] = $answer->user_id;
                            }

                            $options[$opt['id']] = [
                                'title' => $opt['option'],
                                'vote_count' => count(array_unique($yn_users)),
                                'total' => $total,
                                'users' => array_unique($yn_users)
                            ];

                        }
                    }
                }
            }

            $result[] = [
                'id' => $question->id,
                'type' => $question->response_type_id,
                'rank' => $question->rank,
                'num' => $question->num,
                'optional' => $question->optional,
                'title' => $question->question,
                'options' => $options
            ];
        }

        $items = Survey::findOrFail($this->report->survey_id);

        $items->result = $result;
//error after this comment
        $items->totalSent = $tot;
        $items->totalAnswered = $totalAnswered;

        $name = str_replace(':', '', $items->name);
        $counter = 1;

        while (Storage::disk('report_upload')->exists($name . '.xlsx')) {
            $name .= $counter;
            $counter++;
        }

        Excel::store(new SurveyReport($items), $name . '.xlsx', 'report_upload');

        if (Storage::disk('report_upload')->exists($name . '.xlsx')){
            $job_request_report = JobRequestReport::where('survey_id', $this->report->id)
                ->where('request_id', $this->request_id)->first();

            $job_request_report->report_name = $name;
            $job_request_report->processed = true;
            $job_request_report->save();
        }

Why am I getting this error?

Activity icon

Replied to Getting 404 After Dispatching Job

This is the full code

        $now = Carbon::now();

        $usertype = auth()->user()->getUserTypeHighest();

        if ($usertype === 1) {
            $report = Evaluation::with('survey')
                ->whereDate('report_date', '<=', $now)
                ->whereDate('report_end', '>=', $now)
                ->where('report', true)
                ->get();
        } else if ($usertype === 2 || $usertype === 3) {
            $report = Evaluation::with('survey')
                ->whereDate('report_date', '<=', $now)
                ->whereDate('report_end', '>=', $now)
                ->where('report', true)
                ->whereHas('survey', function ($query) {
                    $query->where('user_id', auth()->user()->id);
                })
                ->get();
        }

        if (count($report) > 0) {
            $job_request = new JobRequest();
            $job_request->user_id = auth()->user()->id;
            $job_request->request_time = $now;
            $job_request->completed = false;
            $job_request->save();

            foreach ($report as $item) {
                $this->dispatch(new DownloadReport($item, $job_request->id));

                $request_reports = new JobRequestReport();
                $request_reports->request_id = $job_request->id;
                $request_reports->survey_id = $item->id;
                $request_reports->processed = false;
                $request_reports->save();
            }

            $this->dispatch(new CheckIfDone($job_request->id));
        }

And the dd does work.

Activity icon

Started a new Conversation Getting 404 After Dispatching Job

I'm getting a 404 error after a job is being dispatched, I'm not sure why.

This is the code, I think I know where the error is happening I did dd('here'); on everyline and the 404 only happens after the Job dispatch.

if (count($report) > 0) {
            $job_request = new JobRequest();
            $job_request->user_id = auth()->user()->id;
            $job_request->request_time = $now;
            $job_request->completed = false;
            $job_request->save();

            foreach ($report as $item) {

//404 error after this line
                $this->dispatch(new DownloadReport($item, $job_request->id));

                $request_reports = new JobRequestReport();
                $request_reports->request_id = $job_request->id;
                $request_reports->survey_id = $item->id;
                $request_reports->processed = false;
                $request_reports->save();

            }

            $this->dispatch(new CheckIfDone($job_request->id));
        }

This is the DownloadReport code

   use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $report;
    protected $request_id;
    public $tries = 3;

    public function __construct(Evaluation $report, $request_id)
    {
        $this->report = $report;
        $this->request_id = $request_id;
    }


    public function handle()
    {
// this is not the full code, it's very long but I'm creating an Excel

        $items = Survey::findOrFail($this->report->id);

        $items['result'] = $result;
        $items['totalSent'] = $tot;
        $items['totalAnswered'] = $totalAnswered;

        $name = str_replace(':', '', $items->name);
        $counter = 1;

        while (Storage::disk('report_upload')->exists($name . '.xlsx')) {
            $name .= $counter;
            $counter++;
        }

        Excel::store(new SurveyReport($items), $name . '.xlsx', 'report_upload');

        if (Storage::disk('report_upload')->exists($name . '.xlsx')){
            $job_request_report = JobRequestReport::where('survey_id', $this->report->id)
                ->where('request_id', $this->request_id)->first();

            $job_request_report->report_name = $name;
            $job_request_report->processed = true;
            $job_request_report->save();
        }
    }

I'm not sure why this is happening, what can I do to fix it?

Apr
14
1 month ago
Activity icon

Replied to Production.ERROR: Undefined Offset: 0

What I'm trying to do there is see if the survey evaluators were saved as a group or as individuals, it saves it differently so that's how I check.

Activity icon

Replied to Production.ERROR: Undefined Offset: 0

sorry this is the log

 production.ERROR: Undefined offset: 0 {"userId":1,"exception":"[object] (ErrorException(code: 0): Undefined offset: 0 at /home/vcubed/public_html/encuestas/vendor/laravel/framework/src/Illuminate/Support/Collection.php:2073)
[stacktrace]
#0 /home/vcubed/public_html/encuestas/vendor/laravel/framework/src/Illuminate/Support/Collection.php(2073): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined offse...', '/home/vcubed/pu...', 2073, Array)
#1 /home/vcubed/public_html/encuestas/app/Jobs/DownloadReport.php(54): Illuminate\Support\Collection->offsetGet(0)

On that line there is this

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

        $Eid = Evaluation::where('survey_id', $this->report->id)->pluck('id')->first();
        $evaluators = EvaluationEvaluator::where('evaluation_id', $Eid)->with('group.users')->get();

//line 54 under this comment
        if ($evaluators[0]->user_id == null) {
            $tot = $evaluators[0]['group']['users']->count();
        } else {
            $tot = $evaluators->count();
        }
Activity icon

Started a new Conversation Production.ERROR: Undefined Offset: 0

I'm getting this error when trying to download all available reports into excels. I did test locally without issues with now on a server I'm getting a 500 error and in the logs the error I get is the title.

This is the controller method

public function downloadAllReports()
    {
        $now = Carbon::now();

        $usertype = auth()->user()->getUserTypeHighest();

        if ($usertype === 1) {
            $report = Evaluation::with('survey')
                ->whereDate('report_date', '<=', $now)
                ->whereDate('report_end', '>=', $now)
                ->where('report', true)
                ->get();
        } else if ($usertype === 2 || $usertype === 3) {
            $report = Evaluation::with('survey')
                ->whereDate('report_date', '<=', $now)
                ->whereDate('report_end', '>=', $now)
                ->where('report', true)
                ->whereHas('survey', function ($query) {
                    $query->where('user_id', auth()->user()->id);
                })
                ->get();
        }

        if (count($report) > 0) {
            $job_request = new JobRequest();
            $job_request->user_id = auth()->user()->id;
            $job_request->request_time = $now;
            $job_request->completed = false;
            $job_request->save();

            foreach ($report as $item) {
                $this->dispatch(new DownloadReport($item, $job_request->id));

                $request_reports = new JobRequestReport();
                $request_reports->request_id = $job_request->id;
                $request_reports->survey_id = $item->id;
                $request_reports->processed = false;
                $request_reports->save();

            }

            $this->dispatch(new CheckIfDone($job_request->id));
        }

        return back();
    }

I have two Jobs: DownloadReport and CheckIfDone

DownloadReport

    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $report;
    protected $request_id;
    public $tries = 3;

    public function __construct(Evaluation $report, $request_id)
    {
        $this->report = $report;
        $this->request_id = $request_id;
    }

    public function handle()
    {
        $items = Survey::findOrFail($this->report->id);

        $name = str_replace(':', '', $items->name);
        $counter = 1;

        while (Storage::disk('report_upload')->exists($name . '.xlsx')) {
            $name .= $counter;
            $counter++;
        }

        Excel::store(new SurveyReport($items), $name . '.xlsx', 'report_upload');

        if (Storage::disk('report_upload')->exists($name . '.xlsx')){
            $job_request_report = JobRequestReport::where('survey_id', $this->report->id)
                ->where('request_id', $this->request_id)->first();

            $job_request_report->report_name = $name;
            $job_request_report->processed = true;
            $job_request_report->save();
        }
    }
}

CheckIfDone

    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

    public function handle()
    {
        $reports = JobRequestReport::where('request_id', $this->id)
            ->where('processed', false)->count();

        if ($reports == 0) {
            $job_request = JobRequest::findOrFail($this->id);
            $job_request->completed = true;
            $job_request->save();

            $user = User::findOrFail(JobRequest::findOrFail($this->id)->user_id);
            $user->notify(new QueueDone($job_request->id,
                'Click to Download.'));
        } else {
            $job_request = JobRequest::findOrFail($this->id);
            $job_request->completed = true;
            $job_request->save();

            $job_reports = JobRequestReport::where('request_id', $job_request->id)->where('processed', false)->get();

            $user = User::findOrFail(JobRequest::findOrFail($this->id)->user_id);

            $user->notify(new QueueDone($job_request->id,
                    'Error in ' . count($job_reports) . ' files. Click here to download.'));
        }
    }

The QueueDone is a Notification that is saved to the DB.

Then I run this method periodically every 60000 ms

    public function getNotifications()
    {
        $user = auth()->user();

        return back()->with('notifications', $user->unreadNotifications);
    }

Why am I getting this error?

Feb
19
2 months ago
Activity icon

Started a new Conversation Chunk Items In V-for

Is there a way to chunk or separate the items in a v-for to show another element in between ? Something like this https://www.sirkensingtons.com/product/mayonnaise they have the first 3 items then another element and then the rest of items?

This is my code for a regular v-for

 <span v-for="(product, index) in products" :key="index">
    <product-component :product="product"></product-component>
</span>

What would be the best way to do this?

Feb
17
2 months ago
Activity icon

Replied to CSRF Token Mismatch On Server

what if it's just imaginary.com? Also isn't this in case I have multiple subdomains, in this case I don't have page subdomains.

Activity icon

Replied to CSRF Token Mismatch On Server

I don't have SESSION_DOMAIN I only have

SESSION_DRIVER=file
SESSION_LIFETIME=120
Activity icon

Started a new Conversation CSRF Token Mismatch On Server

On my local machine I don't get this problem but on the server I always get it. I don't know why or what is causing this to happen. I just updated the code on the server and now like 99 things I do give me this error.

I use Vue + Inertia.js, so this is my html master file

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
   
 <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <link href="{{ asset('css/loading.css') }}" rel="stylesheet">

    <link rel="shortcut icon" type="image/png" href="{{ asset('img/favicon.png') }}"/>

    <link rel="stylesheet" href="{{ asset('/css/fontawesome.min.css') }}">
    <link rel="stylesheet" href="{{ asset('/css/solid.min.css') }}">
    <link href="{{ mix('/css/app.css') }}" rel="stylesheet">
</head>
<body>

    @inertia

    <div class="sk-cube-grid">
        <img src="{{ asset('img/favicon.png') }}" alt="logo loading">
    </div>
    <script src="{{ mix('/js/app.js') }}" defer></script>
</body>
</html>

And in my app.js

let token = document.head.querySelector('meta[name="csrf-token"]');
Vue.http.headers.common['X-Requested-With'] = 'XMLHttpRequest';
Vue.http.headers.common['X-CSRF-TOKEN'] = token.content;
Vue.http.headers.common['Accept'] = 'application/json';

What could be causing this to show up now when it didn't before or on my local project?

Activity icon

Started a new Conversation Get All Products That Belong To A Vendor

I have a provider with brands and these brands have products, I need to from the products point of view grab all the products that belong to a provider. This is the code I have right now but I'm getting this error.

$query = Product::query();

$query->whereHas('brand', function ($query) use ($request) {
    $query->whereHas('vendor', function ($query) use ($request) {
        Log::info($query->where('id', $request->id)->get());
    });
});

The error is

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'brands.vendor_id' in 'where clause' (SQL: select * from vendors where brands.vendor_id = vendors.id and id = 3)

The thing is I do have that collumn

Schema::create('vendors', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('image')->nullable();
            $table->timestamps();
});

Schema::create('brands', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name')->nullable();
            $table->integer('vendor_id')->unsigned();;
            $table->foreign('vendor_id')->references('id')->on('vendors');
            $table->timestamps();
});

Models

//Brand
    public function vendor() {
        return $this->belongsTo(Vendor::class);
    }

//Vendor
    public function brands(){
        return $this->hasMany(Brand::class);
    }

//Product
    public function brand()
    {
        return $this->belongsTo(Brand::class);
    }

What am I doing wrong?

Activity icon

Replied to Understanding This Code Snippet, Debug A $query

great idea, I did comment out this part

$query->whereHas('brand', function ($query) use($request) {
    $query->whereHas('vendor', function ($query) use($request) {
        $query->where('id', $request->id);
    });
});

Now the provider does get all the products but I mean ALL the products, so this part is extremely impotant and when I add the brand then it doesn't work, it sends an empty array again, in this case there is only one brand for this provider so it should return all the products.

If I Log::info($request); then I get this info

 'size' => 
  array (
  ),
  'brand' => 
  array (
  ),
  'page' => '1',
  'paginate' => 'true',
  'per_page' => '25',
  'vendor_id' => '6',
  'range1' => '0',
  'range2' => '7015',
  'id' => '6',
Feb
16
3 months ago
Activity icon

Started a new Conversation Understanding This Code Snippet, Debug A $query

I have the task of debugging some code that isn't mine and quite frankly I have no clue what is happening in this code. The situation is that this code works for everyone else except a specific provider and I don't know why, and I need to find out what is happening.

This is the method in my controller

public function postData(Request $request)
    {
        $query = Product::query();
        $query->whereHas('brand', function ($query) use($request) {
            $query->whereHas('vendor', function ($query) use($request) {
                $query->where('id', $request->id);
            });
        });

        if ($request->has('vendor_id')) {
            $country = session('country');

            $query->whereHas('countryProducts', function ($query) use ($country) {
                $query->where('country_id', $country['id']);
            });
            $query->with([
                'brand.vendor',
                'countryProducts' => function ($query) use ($country) {
                    $query->where('country_id', $country['id']);
                }
            ]);
        } else {
            $query->with([
                'brand.vendor'
            ]);
        }
        if ($request->has('range1')) {
            $query->whereHas('countryProducts', function ($query) use ($request) {
                $query->whereBetween('price', [$request->range1, $request->range2]);
            });
        }
        if ($request->brand) {
            $query->whereIn('brand_id', $request->brand);
        } else {
            $query->with([
                'brand.vendor'
            ]);
        }

        if ($request->size) {
            $query->whereHas('sizes', function ($query) use ($request) {
                $query->whereIn('id', $request->size);
            });
        }

        if ($request->has('term')) {
            $term = '%' . $request->term . '%';
            $query->where(function ($query) use ($term) {
                $query->where('code', 'like', $term)
                    ->orWhere('sku', 'like', $term)
                    ->orWhere('description_spanish', 'like', $term)
                    ->orWhereHas('brand', function ($query) use ($term) {
                        $query->where('name', 'like', $term);
                    })
                    ->orWhereHas('countryProducts', function ($query) use ($term) {
                        $query->where('price', 'like', $term);
                    });

            });
        }

        if ($request->has('sort')) {
            list($sortCol, $sortDir) = explode('|', $request->sort);
            if ($sortCol == 'price') {
                $country = session('country');
                $request->request->remove('sort');

                $query->select([
                    'products.*',
                    'country_product.price as price'
                ])
                    ->join('country_product', function ($join) use ($country) {
                        $join->on('products.id', '=', 'country_product.product_id')
                            ->where('country_product.country_id', $country['id']);
                    })
                    ->orderBy('price','asc');
            }
        }

        if ($request->has('paginate')) {
            return TableVue::arrayOf($request, $query);
        } else {
            return $query->get();
        }
    }

The TableVue arrayOf method

static function arrayOf(Request $request, Builder $query, array $searchField = []) {
        // handle sort option
        self::filters($request, $query, $searchField);
        $perPage = $request->has('per_page') ? (int) $request->per_page : null;
        $pagination = $query->paginate($perPage);
        $pagination->appends([
            'sort' => $request->sort,
            'filter' => $request->term,
            'per_page' => $request->per_page
        ]);

        return response()->json($pagination);
    }

This code is supposed to return a list of products for the provider but it's returning 0 when I know for a fact there are products to be returned (they're visible in the db).

This is the response in the browser console for the provider getting to products

Response {url: "/provider/data?page=1&paginate=true&per_page=25&vendor_id=5&range1=0&range2=7015&id=5", ok: true, status: 200, statusText: "OK", headers: Headers, …}
body: {current_page: 1, data: Array(0), first_page_url: "http://dev.sondel.com/provider/data?per_page=25&page=1", from: null, last_page: 1, …}
bodyText: "{"current_page":1,"data":[],"first_page_url":"http:\/\/dev.sondel.com\/provider\/data?per_page=25&page=1","from":null,"last_page":1,"last_page_url":"http:\/\/dev.sondel.com\/provider\/data?per_page=25&page=1","next_page_url":null,"path":"http:\/\/dev.sondel.com\/provider\/data","per_page":25,"prev_page_url":null,"to":null,"total":0}"
headers: Headers {map: {…}}
ok: true
status: 200
statusText: "OK"
url: "/provider/data?page=1&paginate=true&per_page=25&vendor_id=5&range1=0&range2=7015&id=5"
data: (...)
__proto__: Object

This is the response for a provider that is correctly displaying the products

body: {current_page: 1, data: Array(25), first_page_url: "http://dev.sondel.com/provider/data?per_page=25&page=1", from: 1, last_page: 60, …}
bodyText: "{"current_page":1,"data":[{"id":542,"code":"VTFGR","sku":"VTFGR", ..."
headers: Headers {map: {…}}
ok: true
status: 200
statusText: "OK"
url: "/provider/data?page=1&paginate=true&per_page=25&vendor_id=3&range1=0&range2=7015&id=3"
data: Object
__proto__: Object

I don't know where to start on figuring out why this is happening?

Any ideas?

Activity icon

Replied to PHP Extension Ext-mysql_xdevapi Is Missing, Can't Install Either

I ended up doing composer install --ignore-platform-reqs and that got it working. All the instructions I found were for linux so that wasn't really helpful.

Activity icon

Started a new Conversation PHP Extension Ext-mysql_xdevapi Is Missing, Can't Install Either

I'm trying to run an old project on my computer and get this missing extension error when trying to install composer, I'm trying to follow the instalation page but when I run pecl mysql_xdevapi I get some other errors as well.

Notice: Trying to access array offset on value of type bool in PEAR\REST.php on line 186
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
Could not download from "https://pecl.php.net/get/mysql_xdevapi-8.0.23.tgz", cannot download "pecl/mysql_xdevapi" (Connection to `pecl.php.net:443' failed: Unable to find the socket tr
ansport "ssl" - did you forget to enable it when you configured PHP?)
Error: cannot download "pecl/mysql_xdevapi"
Download failed
install failed

This projects composer require in case it's important

    "require": {
        "php": "^7.1.3",
        "ext-mysql_xdevapi": "*",
        "barryvdh/laravel-dompdf": "^0.8.4",
        "fideloper/proxy": "^4.0",
        "inertiajs/inertia-laravel": "dev-master",
        "laravel/framework": "5.8.*",
        "laravel/tinker": "^1.0",
        "maatwebsite/excel": "^3.1"
    },

I use Windows and Xampp. I have other projects that work without any issues, I'm not sure what to do to fix this.

Feb
09
3 months ago
Activity icon

Replied to PUT Or DELETE Method Not Allowed, Only GET HEAD POST

Thanks, your links were very helpful.

Activity icon

Replied to PUT Or DELETE Method Not Allowed, Only GET HEAD POST

This helped me fix the update. I wasn't sending as FormData at all I was sending the object instead. The delete is still giving me trouble.

Activity icon

Replied to PUT Or DELETE Method Not Allowed, Only GET HEAD POST

This is the same exact code as before I'm just now getting these errors and I have no clue why.

Activity icon

Replied to Quick Question: How Long Does It Take?

That also depends on the experience of the developer, an experienced developer might take less time that a junior would. You're saying the page is just static but does something happen when you click on anything like buttons, images? That takes extra time to do as well.

Also the template you mention has a lot of stuff to it, it's not that simple of a page in my opinion, but then again I'm a Junior.

I guess ask them to specify what 4 weeks means, how many hours a day / week.

Activity icon

Replied to PUT Or DELETE Method Not Allowed, Only GET HEAD POST

Same result, I did do a dd('return') instead of the return and I don't get the error. It has to be the return messing this up somehow.

Activity icon

Replied to PUT Or DELETE Method Not Allowed, Only GET HEAD POST

I'm using https://element.eleme.io/#/en-US/component/form for my form, in their docs it doesn't say I have to do that. I've never had to before. This is my form code

<el-form :model="form" ref="form" :rules="rules" status-icon>
    <el-form-item label="Nombre" prop="name">
        <el-input placeholder="Nombre" v-model="form.name"></el-input>
    </el-form-item>

    <el-button @click="submit()">Guardar</el-button>
</el-form>


//submit method
submit() {
    this.$refs.form.validate(() => {
        this.loading = true;

        if (!this.form.id) {
            this.$inertia.post(this.baseUrl, this.form);
        } else {
            this.$inertia.put(this.baseUrl + '/' + this.form.id, this.form);
        }
    });
},
Activity icon

Replied to PUT Or DELETE Method Not Allowed, Only GET HEAD POST

I am, it's doing 2 requests for some reason, the first one has the correct url / parameter but returns a 302 and the second one doesn't have the correct parameter or url.

Activity icon

Replied to Update In Laravel VueJs

@apex1 I dont use axios but you can use this as a guide. In my edit method I clone the object and set it to the form. The form is where you would create a new item. If the key values are the same for a item being created and one being updated it should work no problem. Say it's a post:{title: '', text: ''} that is how you create it so when you edit it it should be the same parameters post:{title: 'my post', text: 'my text'}.

When saving just do an if else checking for the form.id if it doesn't exist its a new product and if it does exist it's an update.

When using this method you have to pass the item you want to edit, be it the table row item.

import _ from 'lodash';

edit(item) {
    this.form = _.cloneDeep(item);
    this.dialogVisible = true;  //if using dialogBox
},

Hope this helps

Activity icon

Started a new Conversation PUT Or DELETE Method Not Allowed, Only GET HEAD POST

This has happened to me on another project and I just gave up and made everything a post. I want to find out why this is happening. I'm using Vue and Inertia.js. In this case I'm trying to update but the same happens for the delete route. I'm using Laravel 8 in case that is relevant.

The bizarre thing is I get the error but after reloading the item have been successfully edited or deleted, I don't understand the error if it's just gonna do it anyway.

This is my code for the update and delete inertia requests

baseUrl: '/category';

//update
 this.$inertia.put(this.baseUrl + '/' + this.form.id, this.form);

//delete
this.$inertia.delete(this.baseUrl + '/' + $id);

the routes

Route::resource('category', 'CategoryController')->except(['create', 'edit']);

the methods in my controller

public function update(Request $request, $id)
    {
        $request->validate([
            'name' => 'required|max:255|unique:categories,name,' . $id,
            'description' => 'required|max:255',
        ]);

        $category = Category::findOrFail($id);
        $category->name = $request->name;
        $category->description = $request->description;
        $category->save();
        DB::commit();

        return back();
    }

public function destroy($id)
    {
        DB::beginTransaction();
        $category = Category::findOrFail($id);
        $category->delete();
        DB::commit();
        return redirect('/category');
    }

I have both a redirect and just a return back to see if that was causing the issue but it's not.

Also in the networking tab on my browser I can see it has made 2 requests one is to the correct url

Request URL:http://me.massiels/category/3
Request Method: PUT 
Status Code: 302 Found 

and another one that is the one giving me an error

Request URL: http://me.massiels/category
Request Method: PUT 
Status Code: 405 Method Not Allowed

I ran route:cache, route:clear, composer dumpautoload, and route:list the list appears like this

GET|HEAD|category|category.index|[email protected]|web|auth|role:admin 

POST|category|category.store|[email protected]|web|auth|role:admin 

DELETE|category/{category}|category.destroy|[email protected]|web |auth|role:admin

PUT|PATCH|category/{category}|category.update|[email protected]|web|auth|role:admin

GET|HEAD|category/{category}|category.show|[email protected] |web|auth|role:admin

What am I doing wrong, how can I fix this?

Jan
14
4 months ago
Activity icon

Replied to Am I Writing Laravel The Right Way !

Try something like this, I don't usually use pure php so I'm not sure if this will get all the data you need but it's a start

$posts = Post::with('user')->where('id', $post)->get();

Check the docs https://laravel.com/docs/8.x/eloquent#retrieving-models

Activity icon

Started a new Conversation Laravel 8 Resource Route Update And Delete Not Working

For both I get this error

The PATCH method is not supported for this route. Supported methods: GET, HEAD, POST.

The DELETE method is not supported for this route. Supported methods: GET, HEAD, POST.

When I change it to post as suggested I get new errors

The POST method is not supported for this route. Supported methods: PUT, PATCH, DELETE.

The POST method is not supported for this route. Supported methods: DELETE.

My route is like this

Route::resource('category', 'CategoryController')->except(['create', 'show', 'edit']);

I'm using Inertia for my requests

//baseUrl
baseUrl: '/category'


//patch
 this.$inertia.patch(this.baseUrl + '/' + this.form.id, data);

//delete
this.$inertia.delete(this.baseUrl + '/' + $id);

I ran route:cache, route:clear and composer dumpautoload and the same happens. Why is this happening and how can I fix it?

Activity icon

Replied to Am I Writing Laravel The Right Way !

Do you have your Models and relationships setup? That would make your code much shorter.

Activity icon

Replied to DELETE Method Is Not Supported For This Route. Supported Methods: GET, HEAD, POST.

If I change it to post I get another error

The POST method is not supported for this route. Supported methods: DELETE.

Activity icon

Started a new Conversation DELETE Method Is Not Supported For This Route. Supported Methods: GET, HEAD, POST.

I get this error but the item still gets deleted anyway after I refresh the page the item is gone. Why am I getting this error if it's deleting anyway?

I'm using inertia to do the request

this.$inertia.delete(this.baseUrl + '/' + $id);

//edit baseUrl
baseUrl: '/category'

route

Route::resource('category', 'CategoryController')->only(['index', 'store', 'destroy']);

method, it doesn't seem to matter if the category has an image or not, since when trying to delete one with and one without an image I get the same error.

    public function destroy($id)
    {
        $category = Category::findOrFail($id);
        if ($category->image) {
            \Cloudinary\Uploader::destroy($category->public_id);
        }
        $category->delete();
        return redirect('/category');
    }

I already tried route:cache, route:clear and composer dumpautoload with no success.

Why am I getting this error?