msslgomez

msslgomez

Member Since 6 Months Ago

Experience Points
4,950
Total
Experience

50 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 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.

Level 1
4,950 XP
Jun
03
22 hours ago
Activity icon

Replied to RefenceError: Valid Is Not Defined In Method

@m7vm7v Isn't that the point to only login when the form is valid?

Activity icon

Replied to RefenceError: Valid Is Not Defined In Method

@siangboon I installed that globally

Activity icon

Awarded Best Reply on Process Excel To Json

The solution I ended up using was the method in the controller to change the key names to indexes

$users = $request->all();

foreach ($users as $user) {

    //this line creates a new array with the indexes instead of the key names
    $item = array_values($user);

    $dbUser = $this->getUser($item[3]);
    $dbUser->name = $item[1];
    $dbUser->card = $item[4];
    $dbUser->scard = $item[3];

    if (!empty($item[14])) {
        $dbUser->email = $item[14];
    }

    $dbUser->password = Hash::make($item[3]);
    $dbUser->save();
    $user_type_id = $this->getUserId('User');

    UserUserType::insert([
        "user_id" => $dbUser->id,
        "user_type_id" => $user_type_id
    ]);

    $dbUser->save();
}
Activity icon

Replied to Process Excel To Json

The solution I ended up using was the method in the controller to change the key names to indexes

$users = $request->all();

foreach ($users as $user) {

    //this line creates a new array with the indexes instead of the key names
    $item = array_values($user);

    $dbUser = $this->getUser($item[3]);
    $dbUser->name = $item[1];
    $dbUser->card = $item[4];
    $dbUser->scard = $item[3];

    if (!empty($item[14])) {
        $dbUser->email = $item[14];
    }

    $dbUser->password = Hash::make($item[3]);
    $dbUser->save();
    $user_type_id = $this->getUserId('User');

    UserUserType::insert([
        "user_id" => $dbUser->id,
        "user_type_id" => $user_type_id
    ]);

    $dbUser->save();
}
Activity icon

Started a new Conversation RefenceError: Valid Is Not Defined In Method

I'm making a super simple login page with Vue.js and Element-ui but I'm getting the valid is not defined error in my code and I'm not sure why. This is the code of my login page

<template>
    <div>
        <el-card class ="login" shadow="never">
            <el-form :model="form" ref="form" :rules="rules">
                <el-form-item label="Usuario" prop="username">
                    <el-input placeholder="User" v-model="form.username"></el-input>
                </el-form-item>
                <el-form-item label="Contraseña" prop="password">
                    <el-input placeholder="Password" show-password v-model="form.password"></el-input>
                </el-form-item>

                <div v-if="$page.prop.errors">

                    <div v-for="error in $page.prop.errors">
                        <el-alert :closable="false" type="error" title="Ha sucedido un error"> </el-alert>
                    </div>

                </div>
                <div style="text-align: center">
                <el-button type="primary" @click="submit()">Login</el-button>
                </div>

            </el-form>
        </el-card>

        {{$page.prop.errors}}

    </div>
</template>
<script>
    export default {
        data() {
            return {
                form: {
                    username: '',
                    password: ''
                },
                rules: {
                    username: {required: true, message: 'The username is required', trigger:'blur'},
                    password: {required: true, message: 'The password is required', trigger:'blur'}
                }
            }
        },
        methods: {
            submit(){
                this.$refs.form.validate((valid) => {
                    if (valid){
                        this.$inertia.post('/login', {
                            username: this.form.username,
                            password: this.form.password
                        });
                    }
                });

            }
        },
    }
</script>

The error is on the submit method, I'm doing it like the Element-ui docs say https://element.eleme.io/#/en-US/component/form#validation

I've tried the submit like this also but always get the same valid is not defined error

 submit(){
    this.$refs.form.validate((valid) => {
        if (valid){
            this.$inertia.post('/login', {
                username: this.form.username,
                password: this.form.password
            });
        }
    });
}

submit(){
    this.$refs['form'].validate((valid) => {
        if (valid){
            this.$inertia.post('/login', {
                username: this.form.username,
                password: this.form.password
            });
        }
    });
}

How can I fix this?

Activity icon

Started a new Conversation Process Excel To Json

I have this code that processes an excel file to a json array in order to import it to the db, I want to modify it to save the json array a little differently but this code isn't mine so I'm not sure how I can modify it This is the methods I'm using

Upload(name) {
                this.loading = true;
                this.data = [];
                //Reference the FileUpload element.
                var fileUpload = document.getElementById(name);
                var regex = /^([a-zA-Z0-9\s_\.\-:])+(.xls|.xlsx|.csv)$/;
                if (regex.test(fileUpload.value.toLowerCase())) {
                    if (typeof (FileReader) != "undefined") {
                        var reader = new FileReader();

                        //For Browsers other than IE.
                        if (reader.readAsBinaryString) {
                            reader.onload = (e) => {
                                this.ProcessExcel(e.target.result);
                            };
                            reader.readAsBinaryString(fileUpload.files[0]);
                        } else {
                            //For IE Browser.
                            reader.onload = (e) => {
                                var data = "";
                                var bytes = new Uint8Array(e.target.result);
                                for (var i = 0; i < bytes.byteLength; i++) {
                                    data += String.fromCharCode(bytes[i]);
                                }
                                this.ProcessExcel(data);
                            };
                            reader.readAsArrayBuffer(fileUpload.files[0]);
                        }
                        this.send = true;
                    } else {
                        this.$message({
                            type: "error",
                            message: "Este navegodor no soporta HTML5."
                        });
                        this.send = false;
                    }
                } else {
                    this.$message({
                        type: "error",
                        message: "Por favor suba un archivo Excel valido."
                    });
                    this.send = false;
                }
                this.loading = false;
            },
            ProcessExcel(data) {
                this.columns = [];
                this.tableData = [];
                //Read the Excel File data.
                var workbook = xlsx.read(data, {
                    type: 'binary'
                });

                //Fetch the name of First Sheet.
                var firstSheet = workbook.SheetNames[0];

                //Read all rows from First Sheet into an JSON array.
                var excelRows = xlsx.utils.sheet_to_row_object_array(workbook.Sheets[firstSheet]);
                var excelRowsJson = xlsx.utils.sheet_to_json(workbook.Sheets[firstSheet], {raw: true});
                this.xlsx = excelRowsJson;
                console.log(excelRows);
                console.log(excelRowsJson);
                var header = Object.keys(excelRowsJson[0]);

                //Create a HTML Table element.
                var table = document.createElement("table");
                table.border = "1";

                //Add the header row.
                var row = table.insertRow(-1);

                for (var a = 0; a < header.length; a++) {
                    var headerCell = document.createElement("TH");
                    headerCell.innerHTML = header[a];
                    if (a === 0) {
                        this.columns.push({
                            prop: header[a].replace(" ", "-"),
                            label: header[a],
                            width: "200",
                            fixed: "left"
                        });
                    } else {
                        this.columns.push({prop: header[a].replace(" ", "-"), label: header[a], width: "200"});
                    }
                    row.appendChild(headerCell);
                }

                //Add the data rows from Excel file.
                for (var i = 0; i < excelRows.length; i++) {
                    //Add the data row.
                    var row = table.insertRow(-1);
                    var array = {};
                    for (var a = 0; a < header.length; a++) {
                        array[header[a].replace(" ", "_")] = [excelRowsJson[i][header[a]]];
                    }
                    this.tableData.push(array);
                    //Add the data cells.
                    this.data = this.xlsx;
                }
            },

This is the data how it gets saved, this is one example how ever I'm not sure if the excel headers are going to change and since how I'm saving them that is needed I would want to save it without the headers

0: {Textbox73: 1, CLINAM2: "name", Textbox74: "2C", GRPCUN2: 200, Textbox75: 208, …}

I would like to save them like this with the index

{0: 1, 1: "name", 2: "2C", 3: 200, 4: 208, ...}

This is how I'm saving it so you can see what I mean, I would like to ignore the variable names in case they change on the excel but this way they always need to be the name, I would rather use for example $item[3] instead of $item['GRPCUN2'},

$users = $request->all();

        foreach ($users as $item) {
            $dbUser = $this->getUser($item['GRPCUN2']);
            $dbUser->name = $item['CLINAM2'];
            $dbUser->card = $item['Textbox75'];
            $dbUser->scard = $item['GRPCUN2'];

            if (!empty($item['CLIEM2'])) {
                $dbUser->email = $item['CLIEM2'];
            }

            $dbUser->password = Hash::make($item['GRPCUN2']);
            $dbUser->save();
            $user_type_id = $this->getUserId('User');

            UserUserType::insert([
                "user_id" => $dbUser->id,
                "user_type_id" => $user_type_id
            ]);

            $dbUser->save();

        }

Is this possible to omit the headers when processing the excel or can I use the index of the json object instead of the variable name?

Jun
02
1 day ago
Activity icon

Replied to Take Object And Return Array If Ids

@michaloravec I ended up doing something else, but great solution! I wasn't sure if I could do it like that.

Activity icon

Awarded Best Reply on Export Excel From Controller With A Query

The solution is to send the request not through vue but in a simple <a href="download route" /> since this is a binary download. The data above is correct

Activity icon

Replied to Export Excel From Controller With A Query

The solution is to send the request not through vue but in a simple <a href="download route" /> since this is a binary download. The data above is correct

Activity icon

Awarded Best Reply on Download Excel, Showing Symbols In Window

The correct way to do this is instead of using a post request with vue (I was using inertia-vue) to simply do a <a href="download route" /> the rest of the code is correct

Activity icon

Replied to Download Excel, Showing Symbols In Window

The correct way to do this is instead of using a post request with vue (I was using inertia-vue) to simply do a <a href="download route" /> the rest of the code is correct

Activity icon

Awarded Best Reply on Laravel Excel Not Downloading

The solution was that I was sending a post request using inertia-vue and that's why I was getting the error, the correct way is just to do a simple <a href="download route"/>. All the other code is correct

Activity icon

Replied to Laravel Excel Not Downloading

The solution was that I was sending a post request using inertia-vue and that's why I was getting the error, the correct way is just to do a simple <a href="download route"/>. All the other code is correct

Activity icon

Started a new Conversation Take Object And Return Array If Ids

I'm trying to set a multiple select in a form but I need the data to be like this [1, 3] and the data I have right now is

[
   {
      "id":1,
      "name":"SuperAdmin",
      "pivot":{
         "user_id":1,
         "user_type_id":1
      }
   },
   {
      "id":3,
      "name":"Director",
      "pivot":{
         "user_id":1,
         "user_type_id":3
      }
   }
]

This is the code I have in my mounted (I'm using vue) I'm not sure how to return each users user_type as [1, 3] or whatever the relationship data above reflects

if (this.$page.type) {
    this.type = this.$page.type;
    this.form.user_type = this.type.map((element) => {
        console.log(element);
        return {
            value: element.id,
            label: element.name

        }
    });
}

I did try with a relationship in the User Model like this

public function getUserTypes()
    {
        $types = $this->userType;
        $t = [];
        foreach ($types as $type) {
            $t[] = $type->pivot->user_type_id;
        }

        return $t;
    }

When I try to use it I get this error

Call to a member function addEagerConstraints() on array

This is me trying to use it in Eloquent

$user = User::with('userCategory', 'userType', 'getUserTypes')->orderBy('updated_at', 'desc')->get();

How can I get the data formatted to only an array of the user_type_ids?

Activity icon

Started a new Conversation User Types Many To Many Check All User Types

I'm trying to go from a user_type_id as a FK to a many to many pivot table, however I'm confused on how to modify the existing logic I have to check if a user has a certain type, for example it can be super admin, admin, director and user, I want to check and keep the highest ranking one to use to setup the permissions.

This is how I'm doing it for the FK in the User model

public function hasRole($id)
    {
        return $this->user_type_id == $id;
    }

    public function isSuperAdmin()
    {
        return $this->hasRole(UserType::SUPER_ADMIN);
    }

    public function isAdmin()
    {
        return $this->hasRole(UserType::ADMIN);
    }

    public function isDirector()
    {
        return $this->hasRole(UserType::DIRECTOR);
    }

    public function isUser()
    {
        return $this->hasRole(UserType::USER);
    }

How can I modify the hasRole($id) to check all of the roles and return the highest number, they go in this order. So if a user is a superadmin and a director and a user I would like to return 1 for superadmin.

public static $SUPER_ADMIN = 1;
public static $ADMIN = 2;
public static $DIRECTOR = 3;
public static $USER = 4;
May
21
1 week ago
Activity icon

Started a new Conversation Laravel Excel Not Downloading

No matter what I try I can't get the file to download at all

This is the Export file

class ReportExcel implements FromArray, withHeadings
{
    use Exportable;

    protected $items;

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

    public function headings(): array
    {
        return ["Opcion 1", "Opcion 2", "Opcion 3", "Nombres", "Apellidos", "Telefono", "Correo", "Pais", "Pais Otro", "Edad", "Adventista", "Estudia la Biblia", "Peticion", "Fecha"];
    }

    public function array(): array
    {
        $data = [];

        foreach ($this->items as $item) {
            foreach ($item as $i) {
                $option1 = ($i->option_1 == 0) ? 'No' : 'Si';
                $option2 = ($i->option_2 == 0) ? 'No' : 'Si';
                $option3 = ($i->option_3 == 0) ? 'No' : 'Si';

                $country = Country::where('id', $i->country_id)->pluck('name')->first();

                $data[] = [$option1, $option2, $option3, $i->name, $i->lastname, $i->phone, $i->email, $country, $i->country_other, $i->age, $i->adventist, $i->study, $i->petition, $i->date_answered];
            }

        }

        return $data;
    }
}

Route, I'm using a post here because I need to send the data I need to use in order to send the correct data to the export file

 Route::post('/download', '[email protected]');

Method in Controller

public function downloadExcel(Request $request)
    {
        if ($request->country == null) {
            $item = Form::get(['option_1', 'option_2', 'option_3', 'name', 'lastname', 'phone',
                'email', 'country_id', 'country_other', 'age', 'adventist', 'study', 'petition', 'date_answered']);
        } else {
            $item = Form::where('country_id', $request->country)->orderByDesc('created_at')
                ->get(['option_1', 'option_2', 'option_3', 'name', 'lastname', 'phone', 'email', 'country_id', 'country_other', 'age', 'adventist', 'study', 'petition', 'date_answered']);
        }

        $items[] = $item;

//     Neither of these work, they just display a window inside the page with the data in text, not formatted or anything 

        return (new ReportExcel($items))->download('invoices.csv');

//        return Excel::download(new ReportExcel($items), 'reporte.csv');

    }

What am I doing wrong? How can I get this to download a file?

May
20
2 weeks ago
Activity icon

Started a new Conversation Download Excel, Showing Symbols In Window

This is what I have currently

Export class

class ReportExcel implements FromArray, withHeadings
{
    use Exportable;

    protected $items;

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

    public function headings(): array
    {
        return ["Opcion 1", "Opcion 2", "Opcion 3", "Nombres", "Apellidos", "Telefono", "Correo",
            "Pais", "Pais Otro", "Edad", "Adventista", "Estudia la Biblia", "Peticion", "Fecha"];
    }

    public function array(): array
    {
        return $this->items;
    }
}

method in my controller

public function downloadExcel(Request $request)
    {
        if ($request->country == null) {
            $item = Form::get(['option_1', 'option_2', 'option_3', 'name', 'lastname', 'phone',
                'email', 'country_id', 'country_other', 'age', 'adventist', 'study', 'petition', 'date_answered']);
        } else {
            $item = Form::where('country_id', $request->country)->orderByDesc('created_at')
                ->get(['option_1', 'option_2', 'option_3', 'name', 'lastname', 'phone', 'email', 'country_id',
                    'country_other', 'age', 'adventist', 'study', 'petition', 'date_answered']);
        }

        $items[] = $item;
        return (new ReportExcel($items))->download('invoices.csv', Excel::CSV,
            ['Content-Type' => 'text/csv']);
    }

If I change the type of extension (xls, xlsx, csv) they all show different stuff in the same window as the picture below, csv shows the data as text, xls show some info but also a lot of empty boxes instead of letters and xlsx shows weird symbols with almost no data at all, completely unusable I get all these weird symbols like this https://ibb.co/F5dTdPF

How can I fix it so I actually download an excel file? What am I doing wrong?

Activity icon

Started a new Conversation Export Excel From Controller With A Query

This is what I have currently

Export class

class ReportExcel implements FromQuery, withHeadings
{
    use Exportable;

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

    public function query()
    {
        return Form::query()->where('country_id', $this->id);
    }

    public function headings(): array
    {
        return ["Opcion 1", "Opcion 2", "Opcion 3", "Nombres", "Apellidos", "Telefono",
            "Pais", "Pais Otro", "Edad", "Adventista", "Estudia la Biblia", "Peticion"];
    }
}
public function downloadExcel(Request $request)
{
    if ($request->country == null) {
        $items = Form::with('country')->get();
        $ex_title = "Reporte_de_Totales";
    } else {
        $items = Form::where('country_id', $request->country)->with('country')->orderByDesc('created_at')->get();
        $country = Country::where('id', $request->country)->pluck('name')->first();
        $ex_title = "Reporte_para_" + $country;
    }

    return (new ReportExcel((int)$request->country))->download($ex_title, \Maatwebsite\Excel\Excel::XLSX);
}

I get all these weird symbols like this https://ibb.co/F5dTdPF

How can I fix it so I actually download an excel file?

Activity icon

Awarded Best Reply on The GET Method Is Not Supported For This Route. Supported Methods: POST.

This is the solution

downloadExcel() {
    this.$inertia.post('/download',
        {country: this.country}
    );
}

Route::post('/download', '[email protected]');

public function downloadExcel(Request $request)
{
    if ($request->country == null) {
        $items = Form::with('country')->get();
        dd(json_encode($items));
    } else {
        $items = Form::where('country_id', $request->country)->with('country')->orderByDesc('created_at')->get();
        dd(json_encode($items));
    }
}
Activity icon

Replied to The GET Method Is Not Supported For This Route. Supported Methods: POST.

This is the solution

downloadExcel() {
    this.$inertia.post('/download',
        {country: this.country}
    );
}

Route::post('/download', '[email protected]');

public function downloadExcel(Request $request)
{
    if ($request->country == null) {
        $items = Form::with('country')->get();
        dd(json_encode($items));
    } else {
        $items = Form::where('country_id', $request->country)->with('country')->orderByDesc('created_at')->get();
        dd(json_encode($items));
    }
}
Activity icon

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

I don't know what is happening, everywhere this route is set up is a post route but it takes it as a get route. This route is triggered when clicking on a button this is the code

click method on vue

downloadExcel() {
    this.$inertia.post('/download/', this.country);
},

route in web.php

Route::post('/download', '[email protected]');

controller method

public function downloadExcel($id)
{
    if ($id == null) {
        $items = Form::with('country')->get();
        dd(json_encode($items));
    } else {
        $items = Form::where('country_id', $id)->with('country')->orderByDesc('created_at')->get();
        dd(json_encode($items));
    }
}

I've tried doing composer dumpautoload a couple times and even invalidate cashes / restart also a couple times but this stays as a get request.

How can I fix it?

Activity icon

Awarded Best Reply on Eloquent Get Returning An Object Instead Of An Array

@jlrdw I ended up doing this

public function getFiltered($id) {
    $filtered = Form::where('country_id', $id)->with('country')->orderByDesc('created_at')->get();

    $items[] = $filtered;
    return back()->with('success', $items);
}
May
19
2 weeks ago
Activity icon

Replied to Eloquent Get Returning An Object Instead Of An Array

@jlrdw I did leave that out but it also wasn't working with or without the with, I'm not sure why, doing what I put in the code fixed the problem

Activity icon

Replied to Eloquent Get Returning An Object Instead Of An Array

@jlrdw I ended up doing this

public function getFiltered($id) {
    $filtered = Form::where('country_id', $id)->with('country')->orderByDesc('created_at')->get();

    $items[] = $filtered;
    return back()->with('success', $items);
}
Activity icon

Started a new Conversation Eloquent Get Returning An Object Instead Of An Array

I'm trying to send a filtered array to the front-end to use in a table, but I need it to be an array, since the filtered array has only one item inside it returns as a object. How can I fix it so that it always returns as an array irregardless of the amount of items inside?

This is what I have now, I added the toArray() to try but it does nothing to make it into an array.

public function getFiltered($id) {
    $filtered = Form::where('country_id', $id)->orderByDesc('created_at')->get()->toArray();

    return back()->with('success', $filtered);
}
May
18
2 weeks ago
Activity icon

Replied to Get Request From Vue, Save Response To Variable

@click That fixed the error I was getting, but the if I do console.log(this) like you mention it still says undefined, how can I fix that?

Activity icon

Started a new Conversation Get Request From Vue, Save Response To Variable

How can I do a get request from the vue file and get the response and set that to a variable? I was initially trying to do it with inertia-vue but I'm unsure how to do it

This is what I've tried, I haven't had any luck

this.$inertia.replace('/filter/' + this.country, {method: 'get'})
    .then(function (response) {
            this.forms = response;
})

this.$http.get('/filter/' + this.country).then(function (response) {
    if (response.status === '200') {
        this.forms = response;
    }
});

The method that works the most in with inertia-vue, however I get the error

Uncaught (in promise) TypeError: Cannot set property 'forms' of undefined

The thing is forms is set like this in the data return forms: [], so I know it's there. If I do a console.log(response) it says undefined.

This is the controller method, I'm not sure if this is the correct way to return this info

 public function getFiltered($id) {
        $filtered = Form::where('country_id', $id)->get();

        return back()->with('filtered', $filtered);
    }

How can I make this work, get the data and set it to the forms variable?

Activity icon

Replied to Filter Data When A Select Changes

@wingly I added more info to my question

Activity icon

Replied to Filter Data When A Select Changes

I'm loading the data like this, I use inertia-vue and send the data from the controller and in the mounted I set the data I'm sending to a variable and just use it like normal after that

Activity icon

Started a new Conversation Filter Data When A Select Changes

I'm trying to filter a table of items using a select that has all the available item countries, when a country is selected the data would change depending on the country selected. How can I do this filtering using the data selected on the front end?

This is the code I have for the select

 <el-select v-model="country" placeholder="País">
    <el-option
        v-for="item in countries"
        :key="item.id"
        :label="item.name"
        :value="item.id">
    </el-option>
</el-select>

I'm not sure what is the best way to do this, is there a way to send the selected country to the controller and get the returned data to then display it? Or what is the best option?

Edit: This is what I'm trying right now, however it's not working, the forms array doesn't change when the select changes so the data doesn't actually filter

watch: {
    country: function (val) {
        this.$inertia.get('/filter' + this.country)
            .then(
                (res) => {
                    this.forms = res.body;
                })
    }
},

And the route

 Route::get('/filter/{id}', '[email protected]');

Method in the controller

public function getFiltered(Request $request, $id) {
        $filtered = Form::where('country_id', $id)->get();

        return $filtered;
}

What am I doing wrong?

Activity icon

Replied to ResetFields Element-ui Checkbox

@wingly Thanks that was the solution!

Activity icon

Started a new Conversation ResetFields Element-ui Checkbox

I'm trying to clear the form after the user sends it but the recommended this.$refs.Form.resetFields() works on everything except the checkboxes they are still selected. How can I fix it so that they are also reset?

This is the form

<el-form ref="surveyForm" :model="surveyForm" :rules="surveyRules">
    <div style="padding-top: 0.5em">
        <el-checkbox prop="prayer_ck" v-model="surveyForm.prayer_ck"/>
            <span style="padding-left: 0.5em; width: 90%; overflow-wrap: break-word;">
                ORACION 
            </span>
    </div>
    <div style="padding-top: 0.5em">
        <el-checkbox prop="study_ck" v-model="surveyForm.study_ck"/>
            <span style="padding-left: 0.5em; width: 90%; overflow-wrap: break-word;">
                ESTUDIO 
            </span>
    </div>
    <div style="padding-top: 0.5em">
        <el-checkbox prop="choice_ck" v-model="surveyForm.choice_ck"/>
            <span style="padding-left: 0.5em; width: 90%; overflow-wrap: break-word;">
                DECISIÓN 
            </span>
    </div>
</el-form>

<script>
    export default {
        data() {
            return {
                surveyForm: {
                    prayer_ck: false,
                    study_ck: false,
                    choice_ck: false
                },
            },
        },
        methods: {
            submit() {
                this.$refs.surveyForm.validate((valid) => {
                    if (valid) {
                        this.$inertia.post('/submit',
                            this.surveyForm
                        ).then(
                            () => 
                                this.$refs.surveyForm.resetFields()
                                this.loadingSurvey = false
                            },
                            (res) => {
                                
                            }
                        )
                    } else {
                        return false;
                    }

                });
            },
        }

I'm calling the reset in the docs in the submit method seen here (https://element.eleme.io/#/en-US/component/form#validation)

What can I do to fix this?

Activity icon

Replied to Change Default Login Routes

@snapey this is what I have currently, how can I fix it. Right now I have to login twice for it to redirect me to the admin dash

Route::post('login')->name('login.attempt')->uses('Auth\[email protected]');

Route::resource('/', 'DashController');

Route::group(['middleware' => 'auth'], function () {
    Route::get('/admin', '[email protected]');
    Route::get('/logout')->name('logout')->uses('Auth\[email protected]');
});
May
14
2 weeks ago
Activity icon

Started a new Conversation Make Countdown To 6 Pm Everyday

I'm using this component (https://github.com/fengyuanchen/vue-countdown) but I'm unsure how to modify the timer part to countdown to a specific time everyday.

This is the example that I'm using

<countdown :time="2 * 24 * 60 * 60 * 1000">
    <template slot-scope="props">
        <ul style="padding-inline-start: 0px">
            <li class="countdown-name"><span class="countdown-num">{{ props.hours }}</span>Horas</li>
            <li class="countdown-name"><span class="countdown-num">{{ props.minutes }}</span>Minutos</li>
            <li class="countdown-name"><span class="countdown-num">{{ props.seconds }}</span>Segundos</li>
        </ul>
    </template>
</countdown>

I want to use the time the admin sets and it saves like this, these are the settings,

[
   {
      "id":1,
      "video_id":"id edited edited",
      "countdown_time":"18:00:00",
      "created_at":"2020-05-14 15:48:39",
      "updated_at":"2020-05-14 16:09:24"
   }
]

The component also has some data in the <script>, like I said this is the base example from the component site, so I'm confused what all this is really doing and how I can modify it

 data() {
    var now = new Date();
    var newYear = new Date(now.getFullYear() + 1, 0, 1);

    return {
        counting: false,
        time: newYear - now,
    }
},
methods: {
    startCountdown() {
        this.counting = true;
    },
    handleCountdownEnd() {
        this.counting = false;
    },
}

Any help is appreciated, basically I want to modify this component to countdown to 6pm everyday, when the counter is at 6pm then it would just start over.

Activity icon

Replied to Change Default Login Routes

@snapey Thats what I understood when you said this

you have placed the root folder / inside the auth middleware. This means you cannot show any home page content to any user that is not logged in. You should move this route outside of the auth middleware and create a different route for dashboard.

May
13
3 weeks ago
Activity icon

Replied to Filter Information Based On Various Variables

@drewdan I'm trying to filter the data from the front end, like send all the data and then filter it on the front end to and display it straight away on the front end

Activity icon

Started a new Conversation Filter Information Based On Various Variables

I need to take all the forms in the db and filter them based on variables on the forms, for example the form belongs to a country, and has various checkboxes, and other variables like age. I would like to be able to filter the list according to those variables.

The variables I would want to use to filter are

checkbox1 => boolean or null
checkbox2 => boolean or null
checkbox3 => boolean or null
country => foreign_id
age => string
adventist => string
study => string

Later on with the filtered forms I would need to display the information in charts and create reports, any suggestions with this are also appreciated.

For right now I would want to know hat is the easiest way to do the filtering?

Activity icon

Awarded Best Reply on Change Default Login Routes

I removed the prefix and changed the DashController base route to /admin and made the changes in the middleware and Auth controllers and that did it. Thanks for the help.

Activity icon

Replied to Change Default Login Routes

I removed the prefix and changed the DashController base route to /admin and made the changes in the middleware and Auth controllers and that did it. Thanks for the help.

Activity icon

Replied to Change Default Login Routes

@michaloravec now I can't login, the login returns a 200 but nothing happens.

Activity icon

Replied to Change Default Login Routes

@michaloravec This gives me this error

Symfony\Component\Debug\Exception\FatalErrorException Illuminate\Routing\RouteFileRegistrar::register(): Failed opening required 'Array' (include_path='C:\xampp\php\PEAR')

Activity icon

Replied to Change Default Login Routes

@snapey After I move the DashController outside the middleware how would I show the admin dash to the logged in user only?

Activity icon

Started a new Conversation Element-ui Component Label Wrapping

I'm making a simple page but a survey on it, this page is going to mostly be seen on mobile devices so it has to very responsive to size. It's looking ok for now but I'm having a problem with the checkbox component label (https://element.eleme.io/#/en-US/component/checkbox) on my phone the label is to long so I get extra width on the container and it just messes everything up, it makes it so that the user would have to scroll horizontally to see it all and I don't want that to happen, I would like it to wrap into two lines instead.

This is my checkbox, I'll replace the text with something else, but it's about the same length.

<el-checkbox v-model="surveyForm.checkbox3"
                             label="These components use flex for layout, so please make.">
</el-checkbox>

How can I make the wrapping work? If not, how can I rework this so ensure the text behaves that way?

Activity icon

Replied to Change Default Login Routes

@snapey this is a very simple page, the only thing I want to do is change the name that appears in the url from login to something else, I don't want to touch the functionality

Activity icon

Started a new Conversation Change Default Login Routes

I'm trying to create a landing page that is informational and there is a dialog that opens up where the admin can login, however it's not a login page only.

The default routes show up as /login which I don't want. I would like the landing page to have the route \info.

Right now I have the original setup web.php

Route::get('login', 'Auth\[email protected]')->name('login');
Route::post('login')->name('login.attempt')->uses('Auth\[email protected]');

Route::group(['middleware' => 'auth'], function () {
    Route::resource('/', 'DashController');
    Route::get('/logout')->name('logout')->uses('Auth\[email protected]');

});

Authenticate middleware

protected function redirectTo($request)
    {
        if (! $request->expectsJson()) {
            return route('login');
        }
    }

How can I change it? I'm using Laravel 6x.

May
12
3 weeks ago
Activity icon

Replied to Component To Watch A YouTube Live Video On Page

@bugsysha yea it does give me the option

Activity icon

Replied to Component To Watch A YouTube Live Video On Page

@bugsysha That's my question, I know there are a lot of YouTube embed components for vue but I want to know if it's posible to do a live video instead of a regular uploaded video

Activity icon

Started a new Conversation Component To Watch A YouTube Live Video On Page

I would like to know if there is a YouTube Vue component where it's possible to watch a YouTube live video in real time?

This is the dependency I'm looking to use : https://www.npmjs.com/package/vue-youtube

I have done the instalation and the example works but It uses a video-id to get the video, I'm not sure how to get this from a youtube video

This is the example code

<youtube :video-id="videoId" ref="youtube"></youtube>


data() {
    return {
        videoId: 'lG0Ys-2d4MA',
    }
}
computed: {
    player() {
        return this.$refs.youtube.player
    }
},
Apr
23
1 month ago
Activity icon

Replied to How To Only Return Certain Columns From Search

@jlrdw the $now is a variable which is $now = Carbon::now();, so those only show me the forums that belong to me and are inbetween the forum's start and end dates, so the user can only reply between those dates

Activity icon

Awarded Best Reply on How To Only Return Certain Columns From Search

This is the solution I arrived to

 $forum_ans = DiscussionForum::whereHas('group.users', function ($query) use ($user) {
                $query->where('user_id', $user);
            })
            ->whereDate('start_date', '<=', $now)
            ->whereDate('end_date', '>=', $now)
            ->orderBy('updated_at', 'desc')
            ->select(['id', 'theme', 'description', 'anonymous', 'start_date', 'end_date'])
            ->get();