hjortur17

Member Since 3 Years Ago

Grindavík

Experience Points
48,120
Total
Experience

1,880 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
268
Lessons
Completed
Best Reply Awards
3
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 10
48,120 XP
Jan
01
2 weeks ago
Activity icon

Started a new Conversation Problem Upgrading PHP On My Server

Hi, when I try to install PHP 8.0 on my server I get an error. This is the error I'm getting:

Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 http://ppa.launchpad.net/chris-lea/redis-server/ubuntu bionic InRelease
Hit:3 http://ppa.launchpad.net/nginx/development/ubuntu bionic InRelease
Hit:4 http://ppa.launchpad.net/ondrej/apache2/ubuntu bionic InRelease
Hit:5 http://ppa.launchpad.net/ondrej/php/ubuntu bionic InRelease
Get:6 https://repos.sonar.digitalocean.com/apt main InRelease [4875 B]
Hit:7 http://mirrors.digitalocean.com/ubuntu bionic InRelease
Hit:8 http://mirrors.digitalocean.com/ubuntu bionic-updates InRelease
Hit:9 http://mirrors.digitalocean.com/ubuntu bionic-backports InRelease
Get:10 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Err:6 https://repos.sonar.digitalocean.com/apt main InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY DE88104AA4C6383F
Reading package lists...
Dec
21
4 weeks ago
Activity icon

Replied to Array_push() Expects Parameter 1 To Be Array, Null Given

This is now returning an empty array.

$myArray = [];

	$crawler = Goutte::request('GET', 'https://www.borgarleikhus.is/syningar/leikarid-2020-2021/');
	$crawler->filter('.info h3')->each(function ($node) use ($myArray) {
		array_push($myArray, array($node->text() => 'Hallo heimur!'));
	});

	dd($myArray);
Activity icon

Started a new Conversation Array_push() Expects Parameter 1 To Be Array, Null Given

I can't figure out how to create a JSON object like this:

    "results": [
        {
            "busNr": "1",
            "busses": [
                {
                    "unixTime": 1354618575,
                    "x": 64.090668,
                    "y": -21.92904,
                    "from": "Hlemmur",
                    "to": "Klukkuvellir"
                },
                {
                    "unixTime": 1354618575,
                    "x": 64.086315,
                    "y": -21.937813,
                    "from": "Klukkuvellir",
                    "to": "Hlemmur"
                }
            ]
        },
        {
            "busNr": "5",
            "busses": [
                {
                    "unixTime": 1354618563,
                    "x": 64.135644,
                    "y": -21.850126,
                    "from": "Hlemmur",
                    "to": "Elliðabraut / Árvað"
                },
                {
                    "unixTime": 1354618577,
                    "x": 64.143989,
                    "y": -21.913048,
                    "from": "Elliðabraut / Árvað",
                    "to": "Hlemmur"
                }
            ]
        }
    ]

This is what I have been trying to do, but always get this error message array_push() expects parameter 1 to be array, null given

Route::get('/', function() {
	$myArray = array();

	$crawler = Goutte::request('GET', 'https://www.borgarleikhus.is/syningar/leikarid-2020-2021/');
	$crawler->filter('.info h3')->each(function ($node) {
		array_push($myArray, array($node->text() => 'Hallo heimur!'));
	});

	json_encode($myArray);

	return view('welcome');
});
Nov
27
1 month ago
Activity icon

Replied to Create A Watcher To Delete From Database

It is working now. How would I start it on my server? SSH into it and run the command?

Activity icon

Replied to Create A Watcher To Delete From Database

Its a string

The update did work 🙂

Activity icon

Replied to Create A Watcher To Delete From Database

@snapey - Running Laravel 8.4.0, but I get this error while trying to run this command

Command "schedule:work" is not defined.

My expiry_date has the format of d/m/Y (27/11/2020). So does this command work

Activity icon

Replied to Create A Watcher To Delete From Database

@snapey - I'm going to run this daily, just testing. The expiry_date column in Coupon is a string.

I did not run this command php artisan schedule:work. So I don't think I have a cron job setup.

When I run this command: php artisan schedule:run, it deletes all data with today as expiry_date, but it doesn't run again the job. How can I make it run again every minute?

Activity icon

Replied to Create A Watcher To Delete From Database

How do I make the command run the same command every minute? When I ran this command: php artisan schedule:run it only ran it once and not again after another minute.

Here is the command:

protected function schedule(Schedule $schedule)
{
	$schedule->call(function () {
		Coupon::where('expiry_date', Carbon::now()->format('d/m/Y'))->delete();
	})->everyMinute();
}
Activity icon

Started a new Conversation Create A Watcher To Delete From Database

Hi, I have coupons and I want to check every day if some of them have expired (some of them has expiry date), and if they are expired then delete them. What is the best thing to use?

Nov
26
1 month ago
Activity icon

Replied to SQL Query

Thanks alot! Much cleaner code

Activity icon

Replied to SQL Query

@michaloravec - I don't understand how I would move my query over to this scope. This is what I'm trying, but I'm getting this error Undefined variable: type

public function scopeOfType($query, $type, $day)
	{
		return $query->with(['services' => $closure = function ($q) {
					$q->where('servicing', $type);
				}])
				->where('booking_type', 'service')
				->where('dropOffDate', $day)
				->whereHas('services', $closure)
				->orWhere('booking_type', 'storage')
				->where('dropOffDate', $day)
				->whereHas('services', $closure)
				->orderBy('dropOffTime');
	}
Activity icon

Replied to SQL Query

Quick question, do any of you have an idea of how I can use my code better? I'm copy-pasting on for different places, always the same code only difference is two attributes.

This is what I am repeating:

Booking::with(['services' => $closure = function ($query) {
			$query->where('servicing', 'garage')		
		}])
		->where('booking_type', 'service')
		->where('dropOffDate', $today)
		->whereHas('services', $closure)
		->orWhere('booking_type', 'storage')
		->where('dropOffDate', $today)
		->whereHas('services', $closure)
		->orderBy('dropOffTime')
		->get();
Activity icon

Replied to SQL Query

Sorry. So I have two bookings in my bookings table. Both of them have the booking_type = service, but the first one has associated service with servicing = garage and the second one has the servicing = cleaning.

This code is giving me both of these bookings but I'm only trying to get that one with servicing = cleaning.

Here is my migration:

Schema::create('bookings', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedMediumInteger('user_id')->nullable();

            $table->string('name');
            $table->string('email');
            $table->string('phone');

            $table->string('carNumber');
            $table->string('carSize');

            $table->string('dropOffDate');
            $table->string('dropOffTime');
            $table->string('pickUpDate')->nullable();
            $table->string('pickUpTime')->nullable();

            $table->string('numberOfDays')->nullable();
            
            $table->boolean('send_bill')->nullable();
            $table->string('companyName')->nullable();
            $table->string('companyId')->nullable();

            $table->string('discountUsed')->nullable();
            $table->string('discountValue')->nullable();
            $table->string('discountPrice')->nullable();

            $table->string('priceForServices');
            $table->string('priceForStorage');
            $table->unsignedMediumInteger('price');

            $table->boolean('paid')->default(0);

            $table->string('korta_authcode')->nullable();
            $table->string('cardbrand')->nullable();
            $table->string('card4')->nullable();

            $table->boolean('accepted_terms');

            $table->string('booking_type');
            
            $table->string('randomKey')->unique();

            $table->timestamps();
        });

Schema::create('services', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('carSize');
            $table->string('title');
            $table->string('category');
            $table->integer('price');
            $table->boolean('visible');
            $table->string('servicing');
            $table->timestamps();
        });

Schema::create('booking_service', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('booking_id');
            $table->unsignedBigInteger('service_id');
            $table->timestamps();

            $table->unique(['booking_id', 'service_id']);
        });
Activity icon

Replied to SQL Query

The whereHas is not working. Here is what I'm trying:

I added this column to the services table called servicing, so I'm trying to get all Bookings which has a service with the servicing column set to cleaning.

$cleaningToday = Booking::where('booking_type', 'service')
			->where('dropOffDate', $today)
			->orWhere('booking_type', 'storage')
			->where('dropOffDate', $today)
			->whereHas('services', function (Builder $query) {
				$query->where('servicing', 'cleaning');
			})
			->orderBy('dropOffTime')
			->with('services')
			->get();
Nov
25
1 month ago
Activity icon

Started a new Conversation SQL Query

Hi, is it possible to have a where clause on belongsToMany relationship? I want to only get the Bookings associated with services that have the category garage.

So what I'm trying to do is: Bookings where services->category = garage

Here is my SQL right now:

$today = Carbon::now()->format('d/m/Y');

$garageToday = Booking::where('booking_type', '=', 'service')
	->where('dropOffDate', '=', $today)
	->orderBy('dropOffTime')
	->with('services')
	->get();
Nov
17
2 months ago
Activity icon

Replied to Laravel Package Install Error

Try running this command inside your Laravel project remove ./composer/cache and after that, run composer global update

Activity icon

Replied to Laravel Package Install Error

Make sure that you are inside the correct folder when running your commands.

Activity icon

Replied to Laravel Package Install Error

Try to run: composer self-update

Activity icon

Replied to Laravel Package Install Error

Can you show me your composer.json file?

Activity icon

Replied to How To Create Card With Bootstrap 4?

Just start simple, follow Bootstrap4 documentation on how to make cards, and then add one thing at a time.

<div class="card" style="width: 18rem;">
  <img src="..." class="card-img-top" alt="...">
  <div class="card-body">
    <h5 class="card-title">Card title</h5>
    <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
    <a href="#" class="btn btn-primary">Go somewhere</a>
  </div>
</div>

This is a simple card.

Here is a link to there documentation on cards: https://getbootstrap.com/docs/4.5/components/card/

Activity icon

Replied to Laravel Package Install Error

What were you doing when this error came up? Did you install something or change something in the composer.json file?

Activity icon

Replied to CORS Problem Laravel API On POST Request

Have you tried making your own middleware for handling CORS? You can follow this tutorial of how to do it, https://medium.com/@abdoumjr/laravel-cors-middleware-58d08048cc74

Activity icon

Replied to Laravel Package Install Error

Try this, the composer.json file is most likely broken.

1. remove ./composer/cache folder
2. run composer global update
Nov
10
2 months ago
Activity icon

Replied to Finding The Total Divs Which Has A Specific Element

@seaniz - You might be want to do something like this,


let checkedElements = 0;
let uncheckedElements = 0;

for (i = 0; i < document.getElementByClass('choices').length; i++) { 
	if ([i].checked) {
		checkedElements += 1;
	} else {
		uncheckedElements += 1;
	}
}

Activity icon

Replied to How To Slip Pop Up Box As The Page Is Scrolled

@lilo - Are you trying to make the div fade away when the user scrolls?

Activity icon

Replied to Page Title In The Layout File Via Currently Active Menu List Item

@uniquehope - My thought of using the component was similar to @newbie360 solution. Then you can make components for the layout.

Here is an example:

<!doctype html>
<html lang="is">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta name="csrf-token" content="{{ csrf_token() }}">

	<title>{{ $title }}</title>

</head>
<body>
	<div id="app">
		{{ $header }}

		<main>
			{{ $slot }}
		</main>

		{{ $footer }}
	</div>
</body>
</html>

And then when you would use the layout, you could do something like this:

menu

<ul>
	<li>
		<x-slot name="title">Server Error</x-slot>
	</li>
</ul>
Nov
09
2 months ago
Activity icon

Replied to Page Title In The Layout File Via Currently Active Menu List Item

I might want to create a Laravel component, https://laravel.com/docs/8.x/blade#components. And then connecting the menu item to the title of the page.

Activity icon

Replied to Redirect After Axios Method Submit On Successful Result

You could do the validation on the backend and then catch the error if the validation failed, but if it passed then you would do something.

submitMobile(){
      axios.post('/customer/send-sms', {
        mobile: this.mobile
      })
          .then(response => {
           // Validation did NOT fail, do something
          })
          .catch(function (error) {
            // Validation DID fail, do something
          });
    }
Activity icon

Replied to How To Install A Classy JS Script On A Page?

Make sure that your event-bus.js and analytics-manager.js are in the same folder

Activity icon

Replied to Contact Form With Notification (email To Sender)

@ziben69 - You could use Laravel Notifications. Read more here: https://laravel.com/docs/8.x/notifications

And I think you are looking for something like the Mail Notifications. Read more here: https://laravel.com/docs/8.x/notifications#mail-notifications

Activity icon

Awarded Best Reply on Vue Js Form Data Returns Undefined

@farshadf - Why not use Axios to do this call? Then you won't need to insert the csrf token using prop and then bind it to input. Then you can add this line to your bootstrap.js file:

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

And then for your input, I would recommend to use v-model. So your input would look like this:

<input class="form-control send-sms-btn" v-model="mobile"  v-validate="'required:11'" placeholder="_ _ _ _">

And if you would go with Axios for this, your script would look something like this:

 export default {
        props: [ 'route' ],

        data: function () {
            return {
                mobile: ''
            }
        },

        methods: {
	  	axios.post('/customer/send-sms', {
				mobile: this.mobile
		})
		.then(response => {
				// Do something
		})
		.catch(function (error) {
			console.log(error)
		});
	}
}
Activity icon

Replied to Vue Js Form Data Returns Undefined

@farshadf - Do you have Axios installed? How does your bootstrap.js file look like?

Activity icon

Replied to Vue Js Form Data Returns Undefined

@farshadf - What error are you getting?

Activity icon

Replied to Vue Js Form Data Returns Undefined

@farshadf - Why not use Axios to do this call? Then you won't need to insert the csrf token using prop and then bind it to input. Then you can add this line to your bootstrap.js file:

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

And then for your input, I would recommend to use v-model. So your input would look like this:

<input class="form-control send-sms-btn" v-model="mobile"  v-validate="'required:11'" placeholder="_ _ _ _">

And if you would go with Axios for this, your script would look something like this:

 export default {
        props: [ 'route' ],

        data: function () {
            return {
                mobile: ''
            }
        },

        methods: {
	  	axios.post('/customer/send-sms', {
				mobile: this.mobile
		})
		.then(response => {
				// Do something
		})
		.catch(function (error) {
			console.log(error)
		});
	}
}
Nov
07
2 months ago
Activity icon

Awarded Best Reply on Bind Checkbox Checked

I ended up doing it like this:

watch: {
		'booking.car.carSize': function () {
			let services = this.services.cleaning;
			let selected = this.booking.services.selected;

			for (var i = selected.length - 1; i >= 0; i--) {
				if (selected[i].carSize != this.booking.car.carSize) {
					selected.splice(selected[i], 1)
				}
			}

			for (var i = services.length - 1; i >= 0; i--) {
				if (services[i].carSize == this.booking.car.carSize & services[i].title == "Alþrif") {
					this.booking.services.selected.push(services[i]);
				}
			}
		}
	},
Activity icon

Replied to Bind Checkbox Checked

I ended up doing it like this:

watch: {
		'booking.car.carSize': function () {
			let services = this.services.cleaning;
			let selected = this.booking.services.selected;

			for (var i = selected.length - 1; i >= 0; i--) {
				if (selected[i].carSize != this.booking.car.carSize) {
					selected.splice(selected[i], 1)
				}
			}

			for (var i = services.length - 1; i >= 0; i--) {
				if (services[i].carSize == this.booking.car.carSize & services[i].title == "Alþrif") {
					this.booking.services.selected.push(services[i]);
				}
			}
		}
	},
Activity icon

Replied to Bind Checkbox Checked

@gitwithravish - It is storing þ and the simplified version did not work. I need to have v-model, so is my only option to create some kind of method that adds Alþrif to booking.services.selected?

Nov
06
2 months ago
Activity icon

Started a new Conversation Bind Checkbox Checked

Hi, can anyone help me figure out how to make all the checkboxes with the title Alþrif checked? Right now it is only disabled but I need to have it checked as well.

Here is my code:

<label v-for="cleaning in services.cleaning">
	<input type="checkbox" :value="cleaning" v-model="booking.services.selected" :checked="cleaning.title == 'Alþrif' ? true : false" :disabled="cleaning.title === 'Alþrif'">
</label>
Sep
17
4 months ago
Activity icon

Replied to Code Editor

Thanks guys! I will download both and try them out :)

Activity icon

Replied to Code Editor

Sublime Text 3 suites my well. I was just thinking to try another editor which might be more powerful and offers more features :)

Activity icon

Started a new Conversation Code Editor

Hi, I have been using Sublime Text 3 for editing my Laravel projects. But have been thinking to switch over to VS Code, would you recommend it or can you recommend any other code editors?

Aug
09
5 months ago
Activity icon

Awarded Best Reply on My Project Is Updating When I Push New Code

I did ssh into my server and did git pull. That solved it

Activity icon

Replied to My Project Is Updating When I Push New Code

I did ssh into my server and did git pull. That solved it

Activity icon

Started a new Conversation My Project Is Updating When I Push New Code

Hi, my website is running a few commits behind. My master branch is up to date but the server is running old commit. I have to try to Deploy using Forge but nothing happens.

I have tried to clear Application cache, Route cache, Configuration cache, and Compiled views.

Any idea how I can fix it?

Jul
21
5 months ago
Activity icon

Replied to Checkbox Checked

@bugsysha - Yes, via API call

getServices: function () {
			axios.get('/api/get/services')
			.then(response => {
				this.services = response.data;
			});
		}
Activity icon

Replied to Checkbox Checked

@bugsysha - I did add the v-model to my checkboxes, but when I want to push all the already chosen services I get this error:

This is how I'm trying to push to the array:

choosenServices: function () {
	let checkedServices = this.data.services;
	let filtered = _.filter(this.services, (v) => _.includes(checkedServices.map(a => a.id), v.id));

	return filtered.map(function (elem) {
		return this.checkedNames.push(elem.id); // here
	});
}
Jul
20
5 months ago
Activity icon

Started a new Conversation Checkbox Checked

Hi, how can I check a checkbox if a value from an array is the same as an id? I have a edit feature for a booking and it's loop through all services available and then I made a computed prop to see what services was chosen in the first place when the booking was made.

How can I check if any of the id's from already chosen services matches id's from all the services?

Here are my for loop (looping trough all the services available):

<div v-for="service in services" v-if="service.carSize === data.carSize && service.visible">
	<input type="checkbox" :value="service.id">
</div>

This is what I have been trying to see if it's was chosen or not:

:checked="checkedService === service.id" 
this on the input

And here is my method to collect all of the checked services:

checkedService: function () {
	let choosenServices = this.data.services;
	let filtered = _.filter(this.services, (v) => _.includes(choosenServices.map(a => a.id), v.id));

	return filtered.map(function (elem) {
		return elem.id;
	});
}

this returns: [4, 7]
Jul
17
6 months ago