hjortur17

hjortur17

Member Since 2 Years Ago

Grindavík

Experience Points
44,910
Total
Experience

90 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
263
Lessons
Completed
Best Reply Awards
1
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 9
44,910 XP
May
31
1 day ago
Activity icon

Replied to Laravel Component Not Recognising My Variable.

@snapey - I don't understand. But if I remove : in front color I don't get a error message but it dosen't render the color.

Activity icon

Replied to Laravel Component Not Recognising My Variable.

I'm running 7.6.2

Here is the whole error message:

Facade\Ignition\Exceptions\ViewException
syntax error, unexpected '<' (View: /Users/hjorturfreyrlarusson/websites/portfolio/resources/views/components/layout.blade.php)
lluminate\View\Engines\PhpEngine::evaluatePath
resources/views/components/layout.blade.php:33

	@if (app()->environment('production'))
		<!-- Global site tag (gtag.js) - Google Analytics -->
		<script async src="https://www.googletagmanager.com/gtag/js?id=UA-156510698-2"></script>
		<script>
			window.dataLayer = window.dataLayer || [];
			function gtag(){dataLayer.push(arguments);}
			gtag('js', new Date());
 
			gtag('config', 'UA-156510698-2');
		</script>
	@endif
 
	<link rel="stylesheet" href="{{ asset('/css/app.css') }}">
</head>
<body>
	<div class="flex content-between flex-wrap min-h-screen py-8 md:py-16" id="app">
		{{ $slot }}
	</div>
 
	@if (session('flash.color') && session('flash.title') && session('flash.body'))
		<x-flash :color="{{ session('flash.color') }}"> // this line
			<x-slot name="title">{{ session('flash.title') }}</x-slot>
			<x-slot name="body">{{ session('flash.body') }}</x-slot>
		</x-flash>
	@endif
 
	<script src="{{ asset('js/app.js') }}"></script>
</body>
</html>
 

Activity icon

Replied to Help With Json_encode

@tykus - I'm using this package right here, https://github.com/dweidner/laravel-goutte

Activity icon

Replied to Help With Json_encode

Looks nice, but I'm receiving this error:

Call to undefined method Symfony\Component\DomCrawler\Crawler::map()
Activity icon

Replied to Help With Json_encode

@tykus - When I try to use array_combine like this:

dump(array_combine(['title', 'sku', 'description', 'price', 'empty'], $dump));

I get this error message:

array_combine() expects parameter 2 to be array, string given

The code looks like this now:

$result = $crawler->filter('.product-details')->each(function ($node) {
		$dump = json_encode($node->children()->each(function ($product) {
			return $product->text();
		}), JSON_UNESCAPED_UNICODE);

		dump(array_combine(['title', 'sku', 'description', 'price', 'empty'], $dump));
	});
Activity icon

Replied to Help With Json_encode

@tykus - That fixed the language issue. Can you help me figure out how to get the whole title?

Activity icon

Started a new Conversation Help With Json_encode

Hi, I'm using json_encode to generate for me an object for each product I'm scraping from a website. But when I use json_encode it's changes some Icelandic character into some weird characters. Any idea how to fix that?

This: Philips Hue úti hreyfiskynjari


Turns into this: Philips Hue \u00fati hreyfiskynjari

And another thing, is it possible for me to name each object?

For example:

This: "["Philips Hue hreyfiskynjari","HUEOUTDOORSENS","hreyfiskynjari Vatnshelt","7.995 kr.",""]

Would be: "[title => "Philips Hue hreyfiskynjari",sku => "HUEOUTDOORSENS", description => "hreyfiskynjari Vatnshelt",price => "7.995 kr.",""]

Because when I try to get the title now in my blade file, doing this {{ $item[0] }}. It returns ", but not the title.

Activity icon

Replied to Laravel Component Not Recognising My Variable.

@snapey - This how I'm sending the flash session over to the blade file:

if ($status == 200) {
			return redirect("/{$locale}/contact")->with('flash', [
				'color' => 'green',
				'title' => $sucess_title,
				'body' => $sucess_body,
			]);
		} else if ($status == 403) {
			return redirect("/{$locale}/contact")->with('flash', [
				'color' => 'red',
				'title' => $error_title,
				'body' => $error_body,
			]);
		}
Activity icon

Replied to Laravel Component Not Recognising My Variable.

If I do it like this:

<x-flash :color="{{ session('flash.color') }}">

I get this error message.

syntax error, unexpected '<'

in this line - <x-flash :color="{{ session('flash.color') }}">
May
30
2 days ago
Activity icon

Replied to Undefined Variable: Object

This is what I ended up with:

$result = $crawler->filter('.product-details')->each(function ($node) {
		return json_encode($node->children()->each(function ($product) {
			return $product->text();
		}));
	});

	foreach ($result as $item) {
		echo $item;
	}
Activity icon

Replied to Undefined Variable: Object

So this:

$crawler->filter('.product-details')->each(function ($node) {
		$object = json_encode($node->children()->each(function ($product) {
			return $product->text();
		}));

		dump(json_decode($object));
	});

Returns this:

array:5 [▼
  0 => "Philips Hue úti hreyfiskynjari"
  1 => "HUEOUTDOORSENS"
  2 => "Nákvæmur hreyfiskynjari Fjölbreyttar stillingar Þráðlaus skynjari Vatnshelt"
  3 => "7.995 kr."
  4 => ""
]
array:5 [▼
  0 => "NanoLeaf viðbótar snjalllýsing - 3 stk"
  1 => "NL3300666"
  2 => "Fyrir NanoLeaf Viðbótarlýsing Þarfnast stjórnstöðvar 3 stk í pakka"
  3 => "8.995 kr."
  4 => ""
]

And I want to loop through this. I'm not familiar enough with map to know it that's the right move.

Activity icon

Started a new Conversation Undefined Variable: Object

Hi, can anybody help me figure out why the variable object is undefined?

$crawler->filter('.product-details')->each(function ($node) {
		return $object = json_encode($node->children()->each(function ($product) {
			return $product->text();
		}));
	});

	dump($object);
Activity icon

Replied to Laravel Component Not Recognising My Variable.

@bobbybouwmann - This is the current status of the code.

layout.blade.php

@if (session('flash.color') && session('flash.title') && session('flash.body'))
	<x-flash color="{{ session('flash.color') }}">
		<x-slot name="title">{{ session('flash.title') }}</x-slot>
		<x-slot name="body">{{ session('flash.body') }}</x-slot>
	</x-flash>
@endif
flash.blade.php

<div class="bg-{{ $color }}-100" role="alert">
	<div class="flex items-center">
		<div class>
			<svg>
		</div>
		<div class="flex-1 px-2">
			<p class="text-{{ $color }}-500">{{ $title }}</p>
			<p>{{ $body }}</p>
		</div>
	</div>
</div>
Activity icon

Replied to Laravel Component Not Recognising My Variable.

Can anybody help me with this?

Activity icon

Replied to How To Create A Tailwind.css File From A Config File

I did understand this like he was looking for the command. My misunderstanding.

Activity icon

Awarded Best Reply on Use Goutte To Scrap Multiple Data From Single Div

I was able to figure this out.

$crawler = Goutte::request('GET', 'https://elko.is/snjallheimilid/snjallperur');

$crawler->filter('.product-details')->each(function ($node) {
	$object = json_encode($node->children()->each(function ($product) {
		return $product->text();
	}));

	dump(json_decode($object));
});

return view('welcome');
Activity icon

Replied to Use Goutte To Scrap Multiple Data From Single Div

I was able to figure this out.

$crawler = Goutte::request('GET', 'https://elko.is/snjallheimilid/snjallperur');

$crawler->filter('.product-details')->each(function ($node) {
	$object = json_encode($node->children()->each(function ($product) {
		return $product->text();
	}));

	dump(json_decode($object));
});

return view('welcome');
Activity icon

Replied to How To Create A Tailwind.css File From A Config File

@connecteev - This might help

  1. Install Tailwind:
# Using npm
npm install tailwindcss

# Using Yarn
yarn add tailwindcss
  1. Add Tailwind to your CSS
@tailwind base;

@tailwind components;

@tailwind utilities;
  1. Create your Tailwind config file
npx tailwindcss init
Activity icon

Replied to Use Goutte To Scrap Multiple Data From Single Div

Can anybody else help me with this?

May
24
1 week ago
Activity icon

Replied to Use Goutte To Scrap Multiple Data From Single Div

@michaloravec - This is my first time working with this. Can you help me loop through this? I can't figure out how.

$crawler->filter('div > .product-details > .product-name')->first();
$crawler->filter('div > .product-details > .price-button')->last();
Activity icon

Started a new Conversation Use Goutte To Scrap Multiple Data From Single Div

Hi, I'm using Goutte to scrap websites containing prices. I want to know how can I scrap the title of the product and the price in one scrap?

This is the div:

<div class="product-details">
	<h4 class="product-name">Name</h4>
	<a class="price-button">Price</a>
</div>

What I have been doing to scrap a single thing from this div is this:

$crawler = Goutte::request('GET', 'https://elko.is/snjallheimilid/snjallperur');

$crawler->filter('div > .product-details > .price-button')->each(function ($node) {
	dump($node->text());
});

return view('welcome');
May
23
1 week ago
Activity icon

Replied to Issue About An Error

Hi, is trying to use the csrf field here:

 <input type="submit" value="Sign In" value="Sign in" class="signin"> <br>
      {{ csrf_field() }}<br><br>        
          <label for="remember_me">
              <input type="checkbox" name="remember_me" id="remember_me" value="1">Remember Me
          </label>     
Activity icon

Replied to Issue About An Error

You need csrf token in your form and head.

HEAD 

<meta name="csrf-token" content="{{ csrf_token() }}">

FORM

<form>
	@csrf
	
	<input>
</form>
May
22
1 week ago
Activity icon

Replied to Laravel Component Not Recognising My Variable.

Still prints this:

<?php echo e(session('flash.color')); ?>
Activity icon

Replied to Laravel Component Not Recognising My Variable.

@bobbybouwmann - Got an error: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ')'

Activity icon

Started a new Conversation Laravel Component Not Recognising My Variable.

Hi, I have a color variable in the session. But when I render my component (Flash) then it's just print's out this:

<?php echo e(session('flash.color')); ?>

Any idea why this is happening?

layout file
@if (session('flash.color') && session('flash.title') && session('flash.body'))
	<x-flash color="{{ session('flash.color') }}">
		<x-slot name="title">{{ session('flash.title') }}</x-slot>
		<x-slot name="body">{{ session('flash.body') }}</x-slot>
	</x-flash>
@endif
component

<div class="bg-{{ $color }}-100" role="alert">
	<div class="flex items-center">
		<div class="flex-1 px-2">
			<p class="text-base md:text-lg font-bold text-{{ $color }}-500">{{ $title }}</p>
			<p class="text-xs md:text-sm leading-relaxed">{{ $body }}</p>
		</div>
	</div>
</div>
controller 

if ($status == 200) {
	return redirect("/{$locale}/contact")->with('flash', [
		'color' => 'green',
		'title' => $sucess_title,
		'body' => $sucess_body,
	]);
} else if ($status == 403) {
	return redirect("/{$locale}/contact")->with('flash', [
		'color' => 'red',
		'title' => $error_title,
		'body' => $error_body,
	]);
}
May
13
2 weeks ago
Activity icon

Awarded Best Reply on I Need A Little Help With Laravel Language

@michaloravec - Thanks for the help. But this was the solution I ended up with.

{!! nl2br(e(__("case_studies/$work->slug.details"))) !!}

And this is how I fixed the array issue:

@foreach (__("case_studies/$work->slug.project") as $project)	
	<li>{{ $project }}</li>
@endforeach
Activity icon

Replied to I Need A Little Help With Laravel Language

@michaloravec - Thanks for the help. But this was the solution I ended up with.

{!! nl2br(e(__("case_studies/$work->slug.details"))) !!}

And this is how I fixed the array issue:

@foreach (__("case_studies/$work->slug.project") as $project)	
	<li>{{ $project }}</li>
@endforeach
Activity icon

Replied to I Need A Little Help With Laravel Language

So I'm trying to make @lang rend whitespace between lines. For example:

This is what I want it to render out:

lorem ass a asdasds sd 

asdasdasd

But it renders it like this:

lorem ass a asdasds sd asdasdasd

And the second thing is to print out an array of things located inside the lang file

Activity icon

Replied to I Need A Little Help With Laravel Language

Fix it. It was supposed to be rendered.

May
12
2 weeks ago
Activity icon

Started a new Conversation I Need A Little Help With Laravel Language

Hi, I have two questions.

  1. Is it possible to make @lang render spaces? Example:
@lang("case_studies/$work->slug.details") // Change this

{!! nl2br(e(@lang("case_studies/$work->slug.details"))) !!} // To something to this
  1. Is it possible to make @lang render an array?
'project' => [
   'UX',
   'UI',
   'Vefhönnun',
   'Vefforritun'
]
May
09
3 weeks ago
Activity icon

Awarded Best Reply on Use Select To Change Location

Figured it out. A little workaround but it works.

<select>
	@if (strtoupper(Request::segment(1)) == "EN")
		<option value="/en/{{ last(request()->segments()) }}" selected>EN</option>
		<option value="/is/{{ last(request()->segments()) }}">IS</option>
	@else
		<option value="/is/{{ last(request()->segments()) }}" selected>IS</option>
		<option value="/en/{{ last(request()->segments()) }}">EN</option>
	@endif
</select>
Activity icon

Replied to Use Select To Change Location

Figured it out. A little workaround but it works.

<select>
	@if (strtoupper(Request::segment(1)) == "EN")
		<option value="/en/{{ last(request()->segments()) }}" selected>EN</option>
		<option value="/is/{{ last(request()->segments()) }}">IS</option>
	@else
		<option value="/is/{{ last(request()->segments()) }}" selected>IS</option>
		<option value="/en/{{ last(request()->segments()) }}">EN</option>
	@endif
</select>
Activity icon

Started a new Conversation Use Select To Change Location

Hi, I'm adding a new language to my website but I'm struggling to figure out how to make people able to switch between languages. I have been trying to use select and option but I can't figure out how to update my $locale variable.

<select>
	<option value="{{ $locale = "en" }}">EN</option>
	<option value="{{ $locale = "is" }}">IS</option>
</select>
Activity icon

Awarded Best Reply on Variable Does Not Work In Laravel Components

@james_moore - The syntax was correct but I needed to generate a component model by using the artisan command. I followed these instructions: https://laravel.com/docs/7.x/blade#components

Activity icon

Replied to Variable Does Not Work In Laravel Components

@james_moore - The syntax was correct but I needed to generate a component model by using the artisan command. I followed these instructions: https://laravel.com/docs/7.x/blade#components

Activity icon

Replied to Variable Does Not Work In Laravel Components

It's a Laravel component, not a Vue component.

Activity icon

Started a new Conversation Variable Does Not Work In Laravel Components

Hi, I'm passing some variables into my view but my component isn't receiving those variables.

This is how I'm passing it into my view:

return view('pages.index', ['title' => '| Full-Stack Developer', 'loc' => $loc, 'works' => $works]);
Activity icon

Replied to Clearing Cache From Site Users Google Chrome

Laravel has few commands to clear cache:

php artisan route:cache

php artisan cache:clear

php artisan config:cache

php artisan view:clear
Activity icon

Replied to Clearing Cache From Site Users Google Chrome

You can clear the cache like this:

php artisan cache:clear
Activity icon

Replied to <img> Arabic Name

Do you have:

<meta charset="utf-8">
May
01
1 month ago
Activity icon

Started a new Conversation Print Text Like It's Stored In The Database

Hi, how can I print out a text like it's in the database?

For example:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Prints out

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

I am printing out like this now:

{{ $work->details }}
Apr
30
1 month ago
Activity icon

Replied to Tailwindcss Purge

No, in first I thought it was some kind of script Laravel uses to transform .blade files into some .html files. But I think this is meant for Vue JS, I'm only using blade files. @tykus - Can you help me to link to the correct files for production

Activity icon

Started a new Conversation Tailwindcss Purge

Hi, how do you set this up with Laravel? Right now when I run production it erases all tailwindcss away. How do I link to the Laravel files?

tailwind.config.js

module.exports = {
	purge: {
		content: ['./src/**/*.html'] // I think i need to change this...
	},
	theme: {
		extend: {
			height: {
				xl: '25rem'
			}
		},
	},
	variants: {},
	plugins: [],
}
webpack.mix.js

const mix = require('laravel-mix');
const tailwindcss = require('tailwindcss');

 mix
	.js('resources/js/app.js', 'public/js')
	.sass('resources/sass/app.sass', 'public/css').options({
		processCssUrls: false,
		postCss: [ tailwindcss('./tailwind.config.js') ],
	});
Activity icon

Replied to Possible To Not Use JQuery For This?

I get TypeError: null is not an object (evaluating 'document.getElementById('#mobile_nav').addEventListener')

Activity icon

Awarded Best Reply on Animation

Figured it out:

div[role=alert]
	opacity: 100%
	right: -900px
	animation: slideleft 1.5s forwards, slideright 1s forwards 5s

@keyframes slideup
	0%
		bottom: -50px
	100%
		bottom: 0

@keyframes slideleft
	100%
		right: 0

@keyframes slideright
	0%
		right: 0

	100%
		right: -900px
Activity icon

Started a new Conversation Possible To Not Use JQuery For This?

Hi, I'm using jQuery for one small hamburger menu which is only displayed on mobile. Is there any other way to do this without using jQuery?

Best regards

import $ from 'jquery';

$(document).ready(function(){
	$('#mobile_nav').click(function(){
		$('#mobile_nav').toggleClass('mobile_nav_link_active');
	});
});
Activity icon

Replied to Animation

Figured it out:

div[role=alert]
	opacity: 100%
	right: -900px
	animation: slideleft 1.5s forwards, slideright 1s forwards 5s

@keyframes slideup
	0%
		bottom: -50px
	100%
		bottom: 0

@keyframes slideleft
	100%
		right: 0

@keyframes slideright
	0%
		right: 0

	100%
		right: -900px