hjortur17

hjortur17

Member Since 1 Year Ago

Grindavík

Experience Points
34,860
Total
Experience

140 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
228
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

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

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

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

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

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

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

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

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

Level 7
34,860 XP
Sep
23
3 weeks ago
Activity icon

Replied to Sort Array

I installed the hole lodash instead of just two parts of it and used @rouge847 solution and it worked.

Activity icon

Replied to Sort Array

This returns empty object. But the error message I was getting before was: (error during evaluation).

And the this.booking.carSize returns a string ('Fólksbíll' or 'Jepplingur' or 'Jeppi' or 'Yfirstærð').

Then grouped returns

sortedServices:Object
    Fólksbíll:Array[10]
    Jeppi:Array[10]
    Jepplingur:Array[10]
    Yfirstærð:Array[10]
sortedServices:Object
    Fólksbíll:Array[10]
        0:Object
            carMake:"Fólksbíll"
            description:"Alþrif & Bón"
            id:1
            price:14500
        1:Object
        2:Object
        3:Object
        4:Object
        5:Object
        6:Object
        7:Object
        8:Object
        9:Object
    Jeppi:Array[10]
    Jepplingur:Array[10]
    Yfirstærð:Array[10]
Activity icon

Replied to Sort Array

This is also not working:

var grouped = groupBy(this.services, item => item.carMake);

grouped.forEach(function (items) {
    return this.filter(items, item => item.carMake === 'Fólksbíll');
})
Activity icon

Replied to Sort Array

I'm importing it in the beginning.

Like this:

import groupBy from "lodash.groupby";
import lodashFilter from "lodash.filter";
sortedServices: function () {
    var grouped = groupBy(this.services, item => item.carMake);

    return lodashFilter(grouped, this.booking.carSize);
}
Activity icon

Replied to Sort Array

It's not working:

sortedServices: function () {
            var grouped = groupBy(this.services, item => item.carMake);

            return grouped.filter(grouped, this.booking.carSize);
        }
Activity icon

Replied to Sort Array

How would I use it to only add the matching carMake with what the user selected?

Activity icon

Started a new conversation Sort Array

Hi, is it possible to sort an array after a type and then split it up and put into another array. For example:

services:Array[40]
0:Object
    carMake:"Jepplingur"
    description:"Alþrif & Bón"
    id:1
    price:14500
1:Object
    carMake:"Fólksbíll"
    description:"Þrif að utan & Bón"
    id:2
    price:8900
2:Object
    carMake:"Jeppi"
    description:"Þrif að innan"
    id:3
    price:5900

And then add them to sortedServices[]

Activity icon

Replied to For Loop Through Array

Thanks, this worked but @ftiersch solution is more practical.

Activity icon

Started a new conversation For Loop Through Array

Hi, how could I run through an array with objects and for each add an data from the object to another array?

This is the array:

selectedServices:Array[2]
0:Object
    carMake:"Fólksbíll"
    description:"Inni geymsla"
    id:7
    price:990
1:Object
    carMake:"Fólksbíll"
    description:"Vélarþvottur"
    id:4
    price:4000

And this is my for loop right now:

for (var i = 0; i < this.selectedServices; i++) {
    this.selectedServicesPrices.push(this.selectedServices[i].price);
    this.selectedServicesId.push(this.selectedServices[i].id);
}
Sep
22
3 weeks ago
Activity icon

Replied to CREATED_AT By Country

Are you storing the country when a user is created?

Then you can do something like this:

DB::table('users')->latest()->value('created_at');
Activity icon

Replied to Get Count And Average Value Of Related Models

You can use count and avg

Something like this:

$count = Category::with(['amenities.amenity_value'])->count();

$average = Category::with(['amenities.amenity_value'])->avg();
Sep
21
3 weeks ago
Activity icon

Started a new conversation Displaying Picture Depends On The Browser

Is is possible to display .jp2 for Safari but .webp for Chrome and other browser?

Sep
19
4 weeks ago
Activity icon

Started a new conversation Routes

Hi, Im trying to build SPA but I need to make an axios call to one endpoint but I'm using {any}. Any idea how to get pass it for one route?

Route::get('/{any}', function () {
    return view('main');
})->where('any', '.*');

Route::prefix('api')->group(function () {
    Route::get('work/get', '[email protected]');
});
Sep
16
1 month ago
Activity icon

Replied to How To Add Services To Booking In Database

This solved it:

$booking->services()->attach($request->services)

Activity icon

Replied to V-Calendar

Found a better component: https://www.npmjs.com/package/vue-datetime

Activity icon

Replied to Problem With Session

I stopped using session because of problem with it on mobile. Now I just have a steps column in my database to mark where the booking is in the process and then just update it after paying.

Activity icon

Replied to Remove HTML From JSON Object

I stopped using that API service and found another one. Did not need to strip anything from it.

Activity icon

Replied to Vue V-for

Okay, that worked. But how can I get every price under this carMake ? I'm trying to make a table.

<tbody>
    <tr>
        <td>Geymslugjald</td>

        <td>500kr (á dag)</td>
        <td class="py-4 px-6 border-b border-grey-light">500kr (á dag)</td>
        <td class="py-4 px-6 border-b border-grey-light">500kr (á dag)</td>
        <td class="py-4 px-6 border-b border-grey-light">500kr (á dag)</td>
    </tr>
    <tr class="hover:bg-grey-lighter">
        <td class="py-4 px-6 border-b border-grey-light font-bold">Rúðuvökvi</td>

        <td class="py-4 px-6 border-b border-grey-light">1.490kr</td>
        <td class="py-4 px-6 border-b border-grey-light">1.490kr</td>
        <td class="py-4 px-6 border-b border-grey-light">1.490kr</td>
        <td class="py-4 px-6 border-b border-grey-light">1.490kr</td>
    </tr>
    <tr class="hover:bg-grey-lighter">
        <td class="py-4 px-6 border-b border-grey-light font-bold">Alþrif &amp; Bón</td>

        <td class="py-4 px-6 border-b border-grey-light">14.500kr</td>
        <td class="py-4 px-6 border-b border-grey-light">16.500kr</td>
        <td class="py-4 px-6 border-b border-grey-light">17.500kr</td>
        <td class="py-4 px-6 border-b border-grey-light">22.500kr</td>
    </tr>
    <tr class="hover:bg-grey-lighter">
        <td class="py-4 px-6 border-b border-grey-light font-bold">Þrif að utan &amp; Bón</td>

        <td class="py-4 px-6 border-b border-grey-light">8.900kr</td>
        <td class="py-4 px-6 border-b border-grey-light">10.900kr</td>
        <td class="py-4 px-6 border-b border-grey-light">11.900kr</td>
        <td class="py-4 px-6 border-b border-grey-light">16.900kr</td>
    </tr>
    <tr class="hover:bg-grey-lighter">
        <td class="py-4 px-6 border-b border-grey-light font-bold">Þrif að innan</td>

        <td class="py-4 px-6 border-b border-grey-light">5.900kr</td>
        <td class="py-4 px-6 border-b border-grey-light">6.900kr</td>
        <td class="py-4 px-6 border-b border-grey-light">7.900kr</td>
        <td class="py-4 px-6 border-b border-grey-light">8.900kr</td>
    </tr>
    <tr class="hover:bg-grey-lighter">
        <td class="py-4 px-6 border-b border-grey-light font-bold">Inni geymsla</td>

        <td class="py-4 px-6 border-b border-grey-light">990kr (á dag)</td>
        <td class="py-4 px-6 border-b border-grey-light">990kr (á dag)</td>
        <td class="py-4 px-6 border-b border-grey-light">990kr (á dag)</td>
        <td class="py-4 px-6 border-b border-grey-light">990kr (á dag)</td>
    </tr>
</tbody>
Activity icon

Replied to Vue V-for

Sorry I forgot to mention you. Your solution was returning empty array.

Activity icon

Replied to Vue V-for

No, cause if I need to do this for every thing in my array it's going to be a lot of variable. Or do have an idea how to get the correct price for same carMake?

Activity icon

Replied to Vue V-for

I'm getting my services like this:

$services = json_decode(file_get_contents('http://admin.parkandfly.is/apitest/ServicesServiceApiTest'), true);
Activity icon

Replied to Vue V-for

This does just return empty array.

Activity icon

Started a new conversation Vue V-for

Hi, is it possible to only get one instance from Array? For example I have an array that looks like this:

[
    0: {id: 1, carMake: "Fólksbíll", description: "Alþrif & Bón", price: 14500, createdAt: null, …}
    1: {id: 2, carMake: "Fólksbíll", description: "Þrif að utan & Bón", price: 8900, createdAt: null, …}
    2: {id: 3, carMake: "Jepplingur", description: "Þrif að innan", price: 5900, createdAt: null, …}
    3: {id: 4, carMake: "Jepplingur", description: "Vélarþvottur", price: 4000, createdAt: null, …}
    4: {id: 3, carMake: "Jeppi", description: "Þrif að innan", price: 5900, createdAt: null, …}
    5: {id: 4, carMake: "Jeppi", description: "Vélarþvottur", price: 4000, createdAt: null, …}
]

And I'm creating a table and trying to use v-for to print out the carMake but I always get double the title, is it possible to make it only print out one time?

I'm doing it like this now:

<th  v-for="carMake in data" v-text="carMake.carMake"></th>
data() {
    return {
        data: []
    }
},

methods: {
    getPricesFromDatabase() {
        axios.get('/api/services/get')
        .then(response => {
            this.data = response.data;
        });
    }   
}
Sep
13
1 month ago
Activity icon

Started a new conversation Vue Not Passing Data Forward

Hi, I'm trying to use VUE to submit a form after generating some data, but I'm having problem accessing that data on a site which the form redirect's too. But if I hard code the value into the data prop, I goes on to the other website. (The data is added to the form before submitting, I have seen that using vue devtools and just simple inspection, but for some reason it isn't passing along)

Here is the form:

<form action="https://test.netgiro.is/securepay" method="POST" ref="netgiroForm" @submit.prevent="checkNetgiroForm($event)">
    <input type="hidden" name="ApplicationID" :value="netgiroId"/>
    <input type="hidden" name="Iframe" value="false" />
    <input type="hidden" name="Signature" :value="netgiro_signature"/>

    <input type="hidden" name="PaymentSuccessfulURL" value="http://localhost:3000/api/database/booking/update/netgiro"/>
    <input type="hidden" name="PaymentConfirmedURL" value="http://admin.parkandfly.is/apitest/BookingsServiceApiTest/netgiroconfirmbooking"/>
    <input type="hidden" name="PaymentCancelledURL" value="http://localhost:3000/um-okkur"/>

    <input type="hidden" name="ConfirmationType" value="1"/>

    <input type="hidden" name="ReferenceNumber" :value="netgiro_refrence" />
    <input type="hidden" name="TotalAmount" :value="amount" />

    <input type="hidden" name="Items[0].ProductNo" value="1" />
    <input type="hidden" name="Items[0].Name" value="Park and fly" />
    <input type="hidden" name="Items[0].Amount" :value="amount" />
    <input type="hidden" name="Items[0].UnitPrice" :value="amount" />
    <input type="hidden" name="Items[0].Quantity" value="1" />
    
    <button type="submit">Borga</button>
</form>

The data:

data() {
    return {
        netgiro_refrence: '',
        netgiro_link: '',
        netgiroId: '7891-AFD8-56FE2624C4B5',
    }
}

And the method:

methods: {
    checkNetgiroForm(e) {
        e.preventDefault();
        e.stopPropagation();

        this.checkData();

        if (!this.termsChecked) {
            alert('Úpps! Þú þarft að samþykkja skilmálana!');
            return false;
        }

        if (this.errors.length > 0) {
            alert('Úpps! Þú fylltir ekki formið rétt inn!');
            return false;
        }

        axios.post('/api/database/booking/create', {
            carNumber: this.booking.carNumber,
            carSize: this.booking.carSize,
            carMake: this.booking.carMake,
            carType: this.booking.carType,
            carColor: this.booking.carColor,

            name: this.booking.name,
            socialId: this.booking.socialId,
            email: this.booking.email,
            phone: this.booking.phone,

            dropOffDate: String(moment(this.selectedDeliveryDay).format('YYYY-MM-DD')),
            dropOffTime: this.booking.dropOffTime,
            pickUpDate: String(moment(this.selectedPickUpDay).format('YYYY-MM-DD')),
            pickUpTime: this.booking.pickUpTime,

            flightNumber: this.booking.flightNumber,

            numberOfDays: this.numberOfDays,
            priceForDays: this.priceForDays,

            paidPrice: this.amount,

            selectedServicesId: this.selectedServicesId,

            discountCode: this.couponInput,

            step: 1
        })
        .then(response => {
            this.amount = response.data.priceTotalDiscount;
            this.discountValid = response.data.discountValid;

            var key = response.data.bookingRef + '-' + response.data.tokenKorta;

            this.netgiro_refrence = key;

            this.$refs.netgiroForm.submit(); // ref i url 
        })
        .catch(function (error) {});
    },
}
Sep
09
1 month ago
Activity icon

Replied to Vue On Submit

That's only submit the form straight away. Does do my stuff first.

Activity icon

Replied to Vue On Submit

I'm using data that comes from my server to generate data that I need to send over to the other site.

So it looks like this:

  1. Click the button
  2. Runs my method first, save the booking in a database and send over data to use for the other site I'm trying to post to
  3. Generate the necessary data from the data I sent over from my server
  4. Post the html form to the other site. (With the generated data)
Activity icon

Started a new conversation Vue On Submit

Hi, I need my form to do two things. First I need the form do submit to my server and get data back and then post to another site. Any ideas how to do that?

I have tried using .passive but that skips my function and just go directly to the other site. And .prevent does not go to the other site.

Here is my function:

checkNetgiroForm(e) {
            e.preventDefault();
            e.stopPropagation();
            
            this.checkData();

            if (!this.termsChecked) {
                alert('Úpps! Þú þarft að samþykkja skilmálana!');
                return false;
            }

            if (this.errors.length > 0) {
                alert('Úpps! Þú fylltir ekki formið rétt inn!');
                return false;
            }

            axios.post('/api/database/booking/create', {
                carNumber: this.booking.carNumber,
                carSize: this.booking.carSize,
                carMake: this.booking.carMake,
                carType: this.booking.carType,
                carColor: this.booking.carColor,

                name: this.booking.name,
                socialId: this.booking.socialId,
                email: this.booking.email,
                phone: this.booking.phone,

                dropOffDate: String(moment(this.selectedDeliveryDay).format('YYYY-MM-DD')),
                dropOffTime: this.booking.dropOffTime,
                pickUpDate: String(moment(this.selectedPickUpDay).format('YYYY-MM-DD')),
                pickUpTime: this.booking.pickUpTime,

                flightNumber: this.booking.flightNumber,

                numberOfDays: this.numberOfDays,
                priceForDays: this.priceForDays,

                paidPrice: this.amount,

                selectedServicesId: this.selectedServicesId,

                discountCode: this.couponInput,

                step: 1
            })
            .then(response => {
                this.amount = response.data.priceTotalDiscount;
                this.discountValid = response.data.discountValid;

                this.netgiro_refrence = response.data.bookingRef;
            })
            .catch(function (error) {
                
            });

            return false;
        },

And the form:

<form action="https://test.netgiro.is/securepay" method="POST" v-if="this.paymentPicked === 'Netgiro'" @submit="checkNetgiroForm($event)">

    <input type="hidden" name="ApplicationID" :value="netgiroId"/>
    <input type="hidden" name="Iframe" value="false" />
    <input type="hidden" name="Signature" :value="netgiro_signature" />
    <input type="hidden" name="PaymentSuccessfulURL" value="https://parkandfly.is/api/database/booking/update"/>

    <!-- Order header -->
    <input type="hidden" name="ReferenceNumber" :value="netgiro_refrence" />
    <input type="hidden" name="TotalAmount" :value="amount" />

    <!-- Order items -->
    <input type="hidden" name="Items[0].ProductNo" :value="netgiro_refrence" />
    <input type="hidden" name="Items[0].Name" :value="booking.name" />
    <input type="hidden" name="Items[0].Amount" :value="amount" />

    <button type="submit">Borga</button>
</form>
Aug
30
1 month ago
Activity icon

Replied to Mail Not Sending Emails With The Same Domain

I was having a problem with this:

 ->cc('[email protected]')
->cc('[email protected]')

It was always sending mail to the last cc. So I changed to an array and it worked. So now it looks like this:

Mail::to($result['email'])
    ->cc (['[email protected]','[email protected]','[email protected]'])
    ->send(new BookingConfirmed($result));
Activity icon

Replied to Remove HTML From JSON Object

Okay, so I got some of the html out. Now I can't figure out how I can search in the response.

Here is the response:

    8 => array:7 [▼
      "date" => "07:20"
      "flightNumber" => "Geneva"
      "airline" => "FI564"
      "to" => "Icelandair"
      "plannedArrival" => "Departed 07:22"
      "realArrival" => ""
      "status" => null
    ]
    9 => array:7 [▼
      "date" => "07:20"
      "flightNumber" => "Zurich"
      "airline" => "FI568"
      "to" => "Icelandair"
      "plannedArrival" => "Departed 07:21"
      "realArrival" => ""
      "status" => null
    ]
    10 => array:7 [▼
      "date" => "07:25"
      "flightNumber" => "Frankfurt"
      "airline" => "FI520"
      "to" => "Icelandair"
      "plannedArrival" => "Departed 07:19"
      "realArrival" => ""
      "status" => null
    ]

and I have a request for FI520, how can I search in this JSON data?

Aug
28
1 month ago
Activity icon

Replied to Remove HTML From JSON Object

If I only do this: $content =file_get_contents("https://apis.is/flight?language=en&type=departures");

This is the response:

"results":[{"date":"\r\n\t\t\t\t\t\t\t\t\t<a href=\"#\" class=\"btn btn-rounded btn-orange show-departed\"><span>Show</span> departed flights <i class=\"icon-right-open-big\" aria-hidden=\"true\"></i></a>\r\n\t\t\t\t\t\t\t\t\t\t","flightNumber":null,"airline":null,"to":null,"plannedArrival":null,"realArrival":null,"status":null},{"date":"\r\n\t\t\t\t\t\t\t\t\t\t\tNo flights found\r\n\t\t\t\t\t\t\t\t\t\t","flightNumber":null,"airline":null,"to":null,"plannedArrival":null,"realArrival":null,"status":null},{"date":"01:35","flightNumber":"<span class=\"cutoff\" title=\"Madrid\">Madrid</span>","airline":"I23661","to":"<span class=\"cutoff\" title=\"Iberia Express\">Iberia Express</span>","plannedArrival":"<span class=\"cutoff\" title=\"Departed 01:28\">Departed 01:28</span>","realArrival":"\r\n","status":null},{"date":"07:20","flightNumber":"<span class=\"cutoff\" title=\"Munich\">Munich</span>","airline":"FI532","to":"<span class=\"cutoff\" title=\"Icelandair\">Icelandair</span>","plannedArrival":"<span class=\"cutoff\" title=\"Departed 07:23\">Departed 07:23</span>","realArrival":"\r\n","status":null},{"date":"07:20","flightNumber":"<span class=\"cutoff\" title=\"Geneva\">Geneva</span>","airline":"FI564","to":"<span class=\"cutoff\" title=\"Icelandair\">Icelandair</span>","plannedArrival":"<span class=\"cutoff\" title=\"Departed 07:23\">Departed 07:23</span>","realArrival":"\r\n","status":null},{"date":"07:20","flightNumber":"<span class=\"cutoff\" title=\"Zurich\">Zurich</span>","airline":"FI568","to":"<span class=\"cutoff\" title=\"Icelandair\">Icelandair</span>","plannedArrival":"<span class=\"cutoff\" title=\"Departed 07:23\">Departed 07:23</span>","realArrival":"\r\n","status":null


and there is more...
Activity icon

Started a new conversation Find The Next Id In The Database

What is the best way to find the next id in the table? For example, a customer is creating a booking number 119 and I want to log it, how would I find that in the same method I'm storing the booking?

See example:

public function createBooking(Request $request)
    {
        $token = uniqid();
        $booking_ref = uniqid();

        $nextId = Booking::find /////// what do here?

        $booking = Booking::create([
            'carNumber' => $request->input('carNumber'),
            'carSize' => $request->input('carSize'),
            'carMake' => $request->input('carMake'),
            'carType' => $request->input('carType'),
            'carColor' => $request->input('carColor'),

            'name' => $request->input('name'),
            'socialId' => $request->input('socialId'),
            'email' => $request->input('email'),
            'phone' => $request->input('phone'),

            'dropOffDate' => $request->input('dropOffDate'),
            'dropOffTime' => $request->input('dropOffTime'),
            'pickUpDate' => $request->input('pickUpDate'),
            'pickUpTime' => $request->input('pickUpTime'),

            'flightNumber' => $request->input('flightNumber'),

            'numberOfDays' => $request->input('numberOfDays'),
            'priceForDays' => $request->input('priceForDays'),

            'paidPrice' => $request->input('paidPrice'),

            'step' => $request->input('step'),

            'reservation_date' => date("Y-m-d H:i:s"),
            'token_expaire_date' => date("Y-m-d H:i:s"),

            'token_korta' => $token,
            'booking_ref' => $booking_ref
        ]);

        $booking->services()->attach($request->input('selectedServicesId'));

        $key = $booking_ref . '-' . $token;

        $dateTimeNow = date("Y-m-d H:i:s");

        Log::channel('slack')->notice('Bókun hefur stofnuð. Kt: '.($booking->socialId).', Netfang: '.($booking->email).', Bókunarnr.: '.$key.', Dags.: '.$dateTimeNow.', Skref: 1');

        if (request()->wantsJson()) {
            return $key;
        }

        return $key;
    }
Activity icon

Replied to Remove HTML From JSON Object

If I try using your method I get this error: strip_tags() expects parameter 1 to be string, array given

Activity icon

Started a new conversation Remove HTML From JSON Object

I can't figure out how to remove HTML tags from JSON object. I'm getting data from a api but in the api there is some html tags. I have tried to json_decode and stuff but that did not work.

So what is the best way to remove html tags in PHP?

Here is example of the response from the api:

    12 => {#251 ▼
      +"date": "07:40"
      +"flightNumber": "<span class="cutoff" title="Brussels">Brussels</span>"
      +"airline": "FI554"
      +"to": "<span class="cutoff" title="Icelandair">Icelandair</span>"
      +"plannedArrival": "<span class="cutoff" title="Departed 07:50">Departed 07:50</span>"
      +"realArrival": "\r\n"
      +"status": null
    }
    13 => {#252 ▼
      +"date": "07:40"
      +"flightNumber": "<span class="cutoff" title="Berlin Tegel">Berlin Tegel</span>"
      +"airline": "FI528"
      +"to": "<span class="cutoff" title="Icelandair">Icelandair</span>"
      +"plannedArrival": "<span class="cutoff" title="Departed 07:52">Departed 07:52</span>"
      +"realArrival": "\r\n"
      +"status": null
    }

and here is how I'm getting this:

$content = json_decode(file_get_contents("https://apis.is/flight?language=en&type=departures"));

dd($content);
Aug
27
1 month ago
Activity icon

Started a new conversation Click.prevent

I have :submit.prevent="checkPaymentForm()" to try prevent form to submit if you haven't accepted our terms. But if I have this, it prevent the from to open, any ideas how to fix that?

<form method="post" action="/api/database/booking/update" :submit.prevent="checkPaymentForm()">
    <input name="reference" type="hidden" :value="this.bookingId">
    <input name="korta_authcode" type="hidden" :value="this.couponInput">

    <p class="my-4 text-sm">
        <input type="checkbox" v-model="termsChecked">
        Ég samþykki <a href="/skilmalar"</a> Park and fly</p>
    </p>
                                    
    <button type="submit">Klára pöntun</button>
</form>
checkPaymentForm: function (e) {
    if (this.termsChecked) {
        return true;
    } else {
        alert('Úpps! Þú þarft að samþykkja skilmálana!');
    }

    e.preventDefault();
}
Activity icon

Replied to Axios Dosent Redirect.

Figured it out, forgot /api/ in the url

Activity icon

Replied to Axios Dosent Redirect.

I'm I doing something wrong?

Activity icon

Replied to SendGrid

I got it to send to my address but @parkandfly.is is not receiving anything.

Activity icon

Replied to Axios Dosent Redirect.

Okay, I changed it to a form. But the form only redirect's, with no flash message and doesn't update the booking.

<form method="post" action="/database/booking/update">
    <input type="hidden" name="reference" :value="this.bookingId">
    <input type="hidden" name="korta_authcode" value="fritt">
                                    
    <button type="submit">Klára pöntun</button>
</form>
Aug
26
1 month ago
Activity icon

Replied to Axios Dosent Redirect.

I need a Axios post if the value is not 0.

Activity icon

Replied to Axios Dosent Redirect.

<template>
    <div class="w-1/4 bg-green-100 border-l-4 border-green-500 text-green-700 p-4 fixed bottom-0 right-0 rounded-l" style="bottom: 40px" role="alert" v-show="show">
        <p class="font-bold">Takk fyrir að velja Park and fly!</p>
        <p>{{ body }}</p>
    </div>
</template>

<script>
    export default {
        props: ['message'],

        data() {
            return {
                body: '',
                show: false
            }
        },

        created() {
            if (this.message) {
                this.flash(this.message)
            }

            window.events.$on('flash', message => {
                this.flash(message);
            });
        },

        methods: {
            flash(message) {
                this.body = message;
                this.show = true;

                this.hide();
            },

            hide() {
                setTimeout(() => {
                    this.show = false;
                }, 3000);
            }
        }
    }
</script>
window.flash = function (message) {
    window.events.$emit('flash', message);
};
Activity icon

Replied to Axios Dosent Redirect.

I have a flash component. I followed one of Jeffrey's tutorial

Activity icon

Replied to Axios Dosent Redirect.

Sorry, I meant doesn't redirect. But I got that to work, but now I can't get the flash message to run. I did it like this:

.then(response => {
        window.location.href = '/';
                    
        window.events.$emit('flash', 'Bókun þín hefur verið staðfest!');
})

And that shows the flash message just for a tiny sec before redirecting back, is it possible to delay it?

Activity icon

Replied to SendGrid

I always get this in my log:

Failed to authenticate on SMTP server with username "parkandfly" using 2 possible authenticators. Authenticator LOGIN returned Expected response code 250 but got an empty response. Authenticator PLAIN returned Expected response code 250 but got an empty response.

Here is how my .env file looks like:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=parkandfly
MAIL_PASSWORD=SG.******
Activity icon

Replied to Axios Dosent Redirect.

This doesn't run,

if (request()->wantsJson()) {
            return response()->json(['flash' => 'Bókun þín hefur verið gerð!']);
        }
createBooking() {
                axios.post('/api/database/booking/update', {
                    reference: this.bookingId,
                    korta_authcode: 'fritt'
                })
                .then(response => {
                    window.location.replace = 'booking.test/';
                })
                .catch(function (error) {});
            }
Activity icon

Replied to Axios Dosent Redirect.

This doesn't do anything.

Here is the full method:

public function updateBooking(Request $request)
    {
        $temp_booking_ref = substr($request->input('reference'), 0, 13);
        $temp_token = substr($request->input('reference'), 14, 26);

        $token_expaire_date = date("Y-m-d H:i:s");

        $current = Booking::where([
            ['booking_ref', '=', $temp_booking_ref],
            ['token_korta', '=', $temp_token],
            ['step', '=', 1],
        ])->get()->first();

        $keyNow = \DateTime::createFromFormat('Y-m-d H:i:s', $current->token_expaire_date);

        $inAYear = $keyNow->add(new \DateInterval('PT10M'));
        $prevTokenDate = $inAYear;

        $tempDateNow = \DateTime::createFromFormat('Y-m-d H:i:s', date("Y-m-d H:i:s"));

        if ($prevTokenDate < $tempDateNow) {
            return redirect('/')->with('flash', 'Óvænt villa!');
        }

        Booking::where([
            ['booking_ref', '=', $temp_booking_ref],
            ['token_korta', '=', $temp_token],
            ['step', '=', 1]
        ])->update(
            [
                'korta_authcode' => $request->input('korta_authcode'),
                'step' => 2,
                'confirmation_date' => date("Y-m-d H:i:s")
            ]
        );

        Log::channel('slack')->notice('Bókun hefur verið staðfest. Kt: '.($current->socialId).', Bókunarnr.: '.($current->id).', Korta auth_code.: '.($request->input('korta_authcode')).', Skref: 2');
        
        Mail::to($current->email)
            ->cc('[email protected]')
            ->cc('[email protected]')
            ->send(new BookingConfirmed($current));

        if (request()->wantsJson()) {
            return response()->json(['flash' => 'Bókun þín hefur verið gerð!']);
        }

        return redirect('/')->with('flash', 'Bókun þín hefur verið gerð!');
    }
Activity icon

Started a new conversation Axios Dosent Redirect.

I'm trying to redirect after Axios has posted to the server. But when I click on the button it only does the function but doesn't redirect.

Here is the button:

return redirect('/')->with('flash', 'Bókun þín hefur verið gerð!');

And here is the create method:

createBooking() {
    axios.post('/api/database/booking/update', {
        reference: this.bookingId,
        korta_authcode: 'fritt'
    })
    .then(response => {})
    .catch(function (error) {});
}
Aug
25
1 month ago
Activity icon

Started a new conversation SendGrid

I'm trying to setup SendGrid to work with Laravel, do you need any magic trick because it wound verify.

This is the config, SendGrid provide:

Server  smtp.sendgrid.net
Ports   
    25, 587 (for unencrypted/TLS connections)
    465 (for SSL connections)
Username    apikey
Password    YOUR_API_KEY

What is suppose to be in apikey? Is it the name I give the api or just apikey?

Here is what I'm doing in Laravel:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=parkandfly
MAIL_PASSWORD=SG.****

parkandfly is the name of the api

Aug
24
1 month ago
Activity icon

Replied to A Tag Have Href And Click Event.

Okay, thanks!

Activity icon

Replied to CSRF Token Mismatch.

Yes I have it, I have two endpoints.

First one is to create the booking:

public function createBooking (Request $request)
    {
        $token_korta = uniqid();

        $booking_ref = uniqid();

        $booking = Booking::create([
            'carNumber' => $request->input('carNumber'),
            'carSize' => $request->input('carSize'),
            'carMake' => $request->input('carMake'),
            'carType' => $request->input('carType'),
            'carColor' => $request->input('carColor'),

            'name' => $request->input('name'),
            'socialId' => $request->input('socialId'),
            'email' => $request->input('email'),
            'phone' => $request->input('phone'),

            'dropOffDate' => $request->input('dropOffDate'),
            'dropOffTime' => $request->input('dropOffTime'),
            'pickUpDate' => $request->input('pickUpDate'),
            'pickUpTime' => $request->input('pickUpTime'),

            'flightNumber' => $request->input('flightNumber'),

            'numberOfDays' => $request->input('numberOfDays'),
            'priceForDays' => $request->input('priceForDays'),

            'paidPrice' => $request->input('paidPrice'),

            'step' => $request->input('step'),

            'reservation_date' => date("Y-m-d H:i:s"),
            'token_expaire_date' => date("Y-m-d H:i:s"),

            'token_korta' => $token_korta,
            'booking_ref' => $booking_ref
        ]);

        $booking->services()->attach($request->input('selectedServicesId'));

        $key = $booking_ref . '-' . $token_korta;

        $dateTimeNow = date("Y-m-d H:i:s");

        Log::channel('slack')->notice('Bókun hefur stofnuð. Kt: '.($booking->socialId).', Netfang: '.($booking->email).', Bókunarnr.: '.$key.', Dags.: '.$dateTimeNow.', Skref: 1');

        if (request()->wantsJson()) {
            return $key;
        }

        return $key;
    }

This runs without a problem, but then the customer goes over to pay and is redirect back to our site and that runs this script:

public function updateBooking(Request $request)
    {
        $temp_booking_ref = substr($request->input('reference'), 0, 13);
        $temp_token = substr($request->input('reference'), 14, 26);

        $token_expaire_date = date("Y-m-d H:i:s");

        $current = Booking::where([
            ['booking_ref', '=', $temp_booking_ref],
            ['token_korta', '=', $temp_token],
            ['step', '=', 1],
        ])->get()->first();

        $keyNow = \DateTime::createFromFormat('Y-m-d H:i:s', $current->token_expaire_date);

        $inAYear = $keyNow->add(new \DateInterval('PT10M'));
        $prevTokenDate = $inAYear;

        $tempDateNow = \DateTime::createFromFormat('Y-m-d H:i:s', date("Y-m-d H:i:s"));

        if ($prevTokenDate < $tempDateNow) {
            return redirect('/')->with('flash', 'Óvænt villa!');
        }

        Booking::where([
            ['booking_ref', '=', $temp_booking_ref],
            ['token_korta', '=', $temp_token],
            ['step', '=', 1]
        ])->update(
            [
                'korta_authcode' => $request->input('korta_authcode'),
                'step' => 2,
                'confirmation_date' => date("Y-m-d H:i:s")
            ]
        );

        Log::channel('slack')->notice('Bókun hefur verið staðfest. Kt: '.($booking->socialId).', Bókunarnr.: '.$key.', Korta auth_code.: '.($request->input('korta_authcode')).', Skref: 2');
        
        Mail::to($current->email)
            ->cc('[email protected]')
            ->cc('[email protected]')
            ->send(new BookingConfirmed($current));

        return redirect('/')->with('flash', 'Bókun þín hefur verið gerð!');
    }

Note: I'm generating a special string and sending that with in reference and matching that when the customer comes back.

Activity icon

Started a new conversation CSRF Token Mismatch.

Hi, I do not understand why I'm getting this. I have this in my bootstrap.js file:

I have this in the header:

window.axios = require('axios');

window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

window.axios.defaults.withCredentials = true


let token = document.head.querySelector('meta[name="csrf-token"]');

if (token) {
    window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
} else {
    console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
}

and this in my app.js:


require('./bootstrap');

window.Vue = require('vue');

import 'vue-datetime/dist/vue-datetime.css'
import { Datetime } from 'vue-datetime';
import dt from 'luxon/src/datetime.js';

dt.local().toISO();

Vue.component('datetime', Datetime);

Vue.component('booking-form', require('./components/BookingForm.vue').default);
Vue.component('navbar', require('./components/Navbar.vue').default);

Vue.component('flash', require('./components/Flash.vue').default);


window.events = new Vue();

window.flash = function (message) {
    window.events.$emit('flash', message);
};
const app = new Vue({
    el: '#app',
});