MartinZeltin

MartinZeltin

Member Since 2 Years Ago

Experience Points
48,670
Total
Experience

1,330 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
360
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 10
48,670 XP
Oct
22
3 days ago
Activity icon

Started a new Conversation Unknown Action Type When Using Vuex 4.0-beta With Modules

I'm living on the bleeding edge here, I know. But I’m getting this error when using Vuex 4 with modules to dispatch a namespaced action. I’m also using Vite.

It's strange because I came across somewhere that in Vuex 4 you have a new syntax like store.module.dispatch.action() but I'm not sure.

setup() {
    const store = useStore();
    store.dispatch('app/doSomething')
}

vuex.esm-bundler.js:465 [vuex] unknown action type: app/doSomething

This also fails..

setup() {
    const store = useStore();
    store.app.dispatch.doSomething();
}

vuex.esm-bundler.js:465 [vuex] unknown action type: doSomething

Here is my app module

import { createStore } from 'vuex'
 
export default createStore({

namespaced: true,

  state()
  {
    return {
      count: 911
    }
  },

  actions:
  {
      doSomething()
      {
          alert('action doing something..')
      },
  },
})
Oct
21
4 days ago
Activity icon

Replied to Vue.js Vite Has An Option For Https, But I'm Getting Invalid Config

@sinnbeck yes, also I learned that in order to pass arguments to vite when running npm run you need to do it like this...

npm run dev -- --https

–https is the vite option. In npm command first -- means after this is an argument --https, and it executed like vite --https

Activity icon

Replied to Vue.js Vite Has An Option For Https, But I'm Getting Invalid Config

@sinnbeck There is no config file, I just followed the instructions in the docs

$ npm init vite-app <project-name>
$ cd <project-name>
$ npm install
$ npm run dev

The above works without problems.

But this doesn't work..

$ npm run dev --https
Activity icon

Started a new Conversation Vue.js Vite Has An Option For Https, But I'm Getting Invalid Config

Hi, in the Docs for Vite it says this

Starting the server with --https will automatically generate a self-signed cert and start the server with TLS and HTTP/2 enabled.

But when I tried it it shows me invalid config. Am I doing it wrong?

$ npm run dev --https
npm WARN invalid config https-proxy=true
npm WARN invalid config Must be a full url with 'http://'

> [email protected] dev C:\xampp\htdocs\vue-client-laravel-server\client
> vite

vite v1.0.0-rc.4

  Dev server running at:
  > Network:  http://192.168.1.118:3000/
  > Local:    http://localhost:3000/
Oct
20
5 days ago
Activity icon

Replied to Best Practice To Split Laravel Into Frontend And Backend Apps?

@sinnbeck I realize these would be 2 seperate repos? Also what about folder structure? URL? Tokens?

Should I make it /var/www/frontend/ and /var/www/backend/? Or something better?

Activity icon

Started a new Conversation Best Practice To Split Laravel Into Frontend And Backend Apps?

I am looking to split my Laravel app into 2 apps. Frontend Vue.js app and for backend Laravel. But what is the best way of doing this?

  • What is the preferred folder structure for an app like this?
  • What is the best URL for the fronend to call the backend? api.app.com or app.com/api/?
  • How best to configure the server?
  • What about auth? Cookies or Tokens?
Oct
19
6 days ago
Activity icon

Replied to How To Use Vite With Laravel?

@sinnbeck Perhaps maybe it would be better to separate them into 2 different apps (frontend and backend)

But then how would I get them to be under the same address?

For example the frontend Vue app to be under the address of:

https://www.myapp.com/

and backend (Laravel) could be here:

https://www.myapp.com/api/users/1
Activity icon

Started a new Conversation How To Combine Frontend And Backend Links?

If I have seperated my frontend and backend into different apps - Vue.js and Laravel app. How could I make it so that my frontend app would make a call to my backend app (maybe running on different port) under the route of /api/?

For example I have seen it be done like this:

https://www.app.com/api/users/

Here the frontend app is making a call to backend app /api/users but this backend app would be running maybe on a different port?

I don't want my frontend app to be reaching out to http://localhost:8080/users

Activity icon

Replied to How To Use Vite With Laravel?

But how would I use Vite instead?

Activity icon

Started a new Conversation How To Use Vite With Laravel?

Vite is a project from Vue that makes Vue.js development extremely fast. It doesn't have a build step while developing. But I think that by default Laravel uses Mix.js? Is there a way to replace it with Vite?

Oct
17
1 week ago
Activity icon

Replied to Remove Whoops Page On Laravel

I just came across the exact same problem as I was trying to dockerise my app and couldn't figure out what was going on.

P.S. You probably shouldn't set your permissions as 777 but something safer. But this worked for me.

This fixed the problem for me:

sudo chmod -R 777 /home/martins/Server/webserver/var/www/forum/*
Oct
11
2 weeks ago
Activity icon

Replied to How To Avoid Using! Important When I Need To Style A Vuetify Component?

@automica I am using Vuetify and I would like to apply tailwind classes to Vuetify's components, for example like this:

<v-btn class="bg-white rounded-lg p-6">Button</v-btn>

But these classes get ignored because they are not "important" enough. They are overwritten by Vuetify's own classes which seem to have greater importance.

Activity icon

Replied to How To Avoid Using! Important When I Need To Style A Vuetify Component?

@automica but this wouldn't work with tailwind utility classes... :(

Activity icon

Started a new Conversation How To Avoid Using! Important When I Need To Style A Vuetify Component?

Maybe I'm missing something but when I try to apply my own class to a v-btn the style doesn't show unless I add !important (which is a bad practice). How could I style just one component without using important?

<v-btn class="btn-add">
   Add todo
</v-btn>

.btn-add {
    height: 49px !important;
}````
Oct
09
2 weeks ago
Activity icon

Started a new Conversation Should You Go Full-stack Or Only Front End / Backend?

Is it really possible to become a real professional as a full-stack developer? The truth is that if you wanted to take just the front-end or just the back-end path there would be an overwhelming amount of things that you'd need to learn. So you can easily devote yourself to full time back-end and still never reach the end of it, right?

So how can anyone truly learn BOTH (full-stack)?

Is that even possible?

Oct
06
2 weeks ago
Activity icon

Replied to How To Write Code So That When Requirements Change It Doesn't Become A Mess?

@automica Thanks, I'd like to continue this conversation if I may.

Yes, I definitely don't want to be the person who writes 7000 lines of bad code in a single file.

I am curious about a Single Page front-end application. Where I had not anticipated that there would need to be more sub-categories or the printing logic requirements changed to be very different now. So it requires me to re-write a lot of the front-end code. I wonder if this could have been avoided somehow? I am using a front-end framework where everything is split up in nice little components. But when the requirements changed, I still ended up having to change a lot of it. Is this normal or is it due to my bad architecture?

Activity icon

Started a new Conversation How To Write Code So That When Requirements Change It Doesn't Become A Mess?

Very often the requirements change for the application and it becomes hard to change the existing codebase. What are some advice / tips for writing an app that will be easy to change later? How not to hard-code things? Any advice?

For example my boss came to me and said.. oh you know what we actually need this thing to be like this... but it wasn't originally intended for that so I'd need to rewrite half of my code... :(

Activity icon

Started a new Conversation Can I Change Laravel For A Different Framework?

Ok, so I've built my app using Laravel. I have models and controllers and everything. Is it possible to easily change the framework for my app from Laravel to something different like CodeIgniter or CakePHP or Yii?

Or is my app so tightly couple to the Laravel framework that it's not possible to easily switch it out for another?

Oct
02
3 weeks ago
Activity icon

Replied to How To Change DocBlock Comments Color In VSCode?

Nope, still 3 different colors, I'd like it all to be just one color

Activity icon

Started a new Conversation How To Change DocBlock Comments Color In VSCode?

I don't know about you guys but it drives me crazy that my DocBlock comments are in multiple colors. I realize this depends on the theme itself (I am using Atom One Dark). But I would like the comment text to be in one color (gray).

Is there a way to change that without having to change my theme?

Screenshot:

Image of Yaktocat

Sep
29
3 weeks ago
Activity icon

Replied to Vue - What Is The Difference Between Composition API And Simple Imports?

@automica I've seen these but still confused about the difference

Activity icon

Replied to Return View() Doesn't Work When Called From A Function

@sinnbeck I went with this. It is more than 1 line but so far it's the cleanest solution in my opinion..

public function index(Request $request)
{
    if (!$this->userHasDevAccess()) {
        return view('error-page');
    }

    return response()->view('app');
}
Activity icon

Started a new Conversation Vue - What Is The Difference Between Composition API And Simple Imports?

Vue 3.0 is out! Yay! As far as I understand, the Composition API allows for code reuse, right?

So what advantage does the Composition API have over a simple imported class that is shared across components?

Can’t I simply do this if I want to reuse code? Why do I need composition api?

import Shared from './shared.js'

class Shared {
  sharedFunction()
  {
  }
}

export default Shared
Sep
28
3 weeks ago
Activity icon

Replied to Return View() Doesn't Work When Called From A Function

@sinnbeck Is there a way to write the same thing like this? Just one like check..

public function index(Request $request)
{
    $this->showErrorPageIfNoDevAccess();

    return view('index');
}
Activity icon

Started a new Conversation Return View() Doesn't Work When Called From A Function

I wanted to extract some logic into a function but now it's not working. The error-page view doesn't get returned. The same logic works if I don't extract to function.. Why is that?

<?php 
    class IndexController extends Controller
    {
        public function index(Request $request)
        {
            $this->checkDevelopmentAccess();

            return view('index');
        }

        public function checkDevelopmentAccess()
        {
            if (request()->has('dev')) {
                session(['dev' => 'ok']);
                return redirect()->route('index');
            }

            if (!session()->has('dev')) {
                return view('error-page');
            }
        }
    }
?>

Sep
24
1 month ago
Activity icon

Replied to How To Disable Laravel Mix But Still Use Watch?

Oh, looks like I needed to restart my watcher after I updated my webpack.mix.js file. Now it seems to be working.

Activity icon

Replied to How To Disable Laravel Mix But Still Use Watch?

@sinnbeck yes it does. But is there a way to tell mix not to compile anything inside /resources/sass/* ? Even after I cleared everything from webpack.mix.js it still tries to do that...

Activity icon

Replied to How To Disable Laravel Mix But Still Use Watch?

@sinnbeck Well I do want my Vue.js to compile but I don't want to compile any CSS but use them directly from public/css

Activity icon

Replied to How To Disable Laravel Mix But Still Use Watch?

@sinnbeck and here is my package.json where I run npm run watch

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --disable-host-check --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
}
Activity icon

Replied to How To Disable Laravel Mix But Still Use Watch?

@sinnbeck

I haven't changed anything. But I do not see webpack.config.js in my root directory only webpack.mix.js

I'm on Laravel 7.

Image of Yaktocat

Activity icon

Started a new Conversation How To Disable Laravel Mix But Still Use Watch?

I really don't need Laravel Mix but when I delete everything in webpack.mix.js and delete app.scss file I get an error when I run npm run watch that app.scss is not found.

Sep
23
1 month ago
Activity icon

Started a new Conversation Is There More Good Or Bad Code Out There In The Real World?

We are taught to write clean and maintainable code. But I'm just wondering in the real business world, is there more clean / well written code out there or more bad / poorly written code (spaghetti code etc.)? What's to be expected? What is your experience?

Activity icon

Replied to How To Create A Static And Non-static Method On Model?

@a4ashraf thanks, that's what I was looking for!

Activity icon

Started a new Conversation How To Create A Static And Non-static Method On Model?

I would like to create a new method on my model where I could call it in 2 ways

class UsersController extends Controller
{
    public function index()
    {
        // Calling statically
        return User::searchByName(request('name'));

        // Calling non-statically
        return User::active()->searchByName(request('name'));
    }
}

But when I create it like this it only works statically

class User extends Model
{
    public static function searchByName($name)
    {
        return self::where('name', 'like', "$name%")
                   ->take(3)
                   ->get()
                   ->pluck('name');
    }
}
Activity icon

Commented on Instant Username Autocompletion: Part 2

There is a Vue.js version of at called vue-at But you will also then need to pull in textarea-caret

Sep
22
1 month ago
Activity icon

Replied to How To Include User Id In $validated Create?

@sinnbeck sure, here it is

public function validateThread()
{
    $validated = $this->validate(request(), [
        'title' => 'required',
        'body' => 'required',
        'channel_id' => 'required|exists:channels,id',
    ]);

    resolve(Spam::class)->detect(request('body'));

    return $validated;
}

and now $validated contains this

array:3 [
  "title" => "Autem quis quia nisi alias."
  "body" => "Eligendi nesciunt error cupiditate esse labore soluta. Nam consequatur aut assumenda ullam eligendi aliquam. Tenetur aliquam occaecati beatae eum voluptas."
  "channel_id" => 1
]
Activity icon

Started a new Conversation How To Include User Id In $validated Create?

I have this store method right now but the create functionality is kind of long, I would like to reduce it to just one line by passing the $validated to create. But the problem is that it doesn't include the user id. Any ideas how this might be solved?

public function store(Request $request)
{
    $validated = $this->validateThread();

    $thread = Thread::create([
        'user_id' => auth()->id(),
        'title' => $request->title,
        'channel_id' => $request->channel_id,
        'body' => $request->body,
    ]);
}

Would be really nice if this could be just one line.

public function store(Request $request)
{
    $validated = $this->validateThread();

    $thread = Thread::create($validated);
}

But the $validated doesn't include the user_id :(

Activity icon

Started a new Conversation No Auto Complete Intelisense In VSCode For PHP?

It looks like my VSCode doesn't autocomplete / suggest a function that has already been used once in a file. It should definitely see it and offer auto complete with tab. I have PHP Intelephense extension installed. This used to work in Sublime text. What am I missing?

Take a look at this screenshot of VSCode vs Sublime

Image of Yaktocat

Sep
21
1 month ago
Activity icon

Replied to How To Format The Object Operator In VSCode?

Maybe I would need to roll my own formatter extension... Looking at the docs makes my head explode.

Activity icon

Started a new Conversation How To Format The Object Operator In VSCode?

I have tried Prettier but it is too "opinionated" for my taste. I am looking for something that could format the object operators to be at the same column. (VSCode has Format on Save)

For example if I have code like this:

// PHP

$post = $post->whereName($name)
         ->whereCount(5)
         ->get();

// JS

let time = moment.now()
    .format('Y-m-d')
    .toString()

then I would like to have my editor automatically format it to this

// PHP

$post = $post->whereName($name)
             ->whereCount(5)
             ->get();
 
// JS

let time = moment.now()
                 .format('Y-m-d')
                 .toString()
Activity icon

Commented on Type Checking JavaScript Files

Next we are going to talk about the refactoring abilities

Hey, you got me on the edge of my seat here...

Sep
20
1 month ago
Activity icon

Replied to Scope Method Is Not Found On Related Model

Oh, I see, each can only be called on Collection

$this->subscriptions()
        ->notFor($reply->user_id)
        ->get()
        ->each->notify($reply);
Activity icon

Replied to Scope Method Is Not Found On Related Model

@marianomoreyra Now I'm getting a different error:

Undefined property: Illuminate\Database\Eloquent\Relations\HasMany::$each

Activity icon

Started a new Conversation Scope Method Is Not Found On Related Model

I'm doing the Forum with TDD series and I'm trying to add a scope filter but Laravel keeps saying that it's not found. What am I missing here?

Method Illuminate\Database\Eloquent\Collection::notFor does not exist

Thread.php


class Thread extends Model
{
    public function addReply($reply)
    {
        $reply = $this->replies()->create($reply);

        $this->subscriptions->notFor($reply->user_id)->each->notify($reply);

        return $reply;
    }

    public function subscriptions()
    {
        return $this->hasMany(ThreadSubscription::class);
    }
}

ThreadSubscription.php

class ThreadSubscription extends Model
{
    public function scopeNotFor($query, $user_id)
    {
        return $query->where('user_id', '<>', $user_id);
    }
}
Sep
18
1 month ago
Activity icon

Replied to How Would You Refactor This Function?

Thanks guys! I'll try to split it into individual methods and see how it goes!

Activity icon

Replied to How Would You Refactor This Function?

@sinnbeck

...and have each piece of the loop inside other methods as well :)

I'm not sure I understand. You mean to repeat the loop in every method? Wouldn't that be duplicate code? Wouldn't it be better to have one loop outside the methods?

Activity icon

Replied to How Would You Refactor This Function?

@sinnbeck I really like your example, very clean. One question though.. Shouldn't there be a foreach loop to print all itmes?

Activity icon

Started a new Conversation How Would You Refactor This Function?

I have a function that prepares a receipt output. But since it has all kinds of conditions it ends up being very long and difficult to understand..

How would one go about refactoring this? Any ideas?

public static function prepare_receipt($printer)
{
	if (self::hasItems($printer['id']))
	{
		$output = '';

		if ($_POST['pre_receipt'])
		{
			$output .= "======== Pre receipt =======\n\n\n";
		}

		/**
		 * Time and table
		 */
		if ($_POST['isTakeaway'] || $_POST["isDeliveryGuys"] || $_POST["isBolt"]) {
			$output .= "Table: " . $_POST['table'] . "\n";
			$output .= "Floor: " . $_POST['floor'] . "\n";
			$output .= "Time: " . $_POST['takeawayTime'] . "\n";

			if ($_POST['order_comment']) {
				$output .= "Comment: " . removeSpecialChars($_POST['order_comment']) . "\n";
			}
		} else {
			$output .= "Table: " . $_POST['table'] . "\n\n";
			$output .= "Floor: " . $_POST['floor'] . "\n\n";

			if ($_POST['order_comment']) {
				$output .= "Comment: " . removeSpecialChars($_POST['order_comment']) . "\n";
			}
		}

		$output .= "------------------------\n";


		/**
		 * Food items
		 */
		foreach ($_POST['orderedItems'] as $orderedItem)
		{
			$has_unprinted_quantity = false;

			if (isset($orderedItem['last_printed_quantity'])) {
				$unprinted_quantity_count = intval($orderedItem['is_printed_quantity']) - intval($orderedItem['last_printed_quantity']);

				if ($unprinted_quantity_count > 0) {
					$has_unprinted_quantity = true;
				}
			}


			if ( ($orderedItem['should_print'] &&
				 !$orderedItem['is_printed'] &&
				  $orderedItem['is_visible']) ||
				  $_POST['pre_receipt'] ||
				  $has_unprinted_quantity)
			{
				if (is_array($orderedItem['printers'])) {
					$in_printer = in_array($printer['id'], $orderedItem['printers']);
				} else {
					$in_printer = in_array($printer['id'], json_decode($orderedItem['printers'], true));
				}

				if (  $in_printer || $_POST['pre_receipt'] )
				{
					if ($orderedItem['is_sidedish'] && !$_POST['pre_receipt']) {
						continue;
					}

					if ($has_unprinted_quantity) {
						$output .= $unprinted_quantity_count . 'x ';
					} else {
						$output .= $orderedItem['quantity'] . 'x ';
					}

					// We ned to split it for multiple lines...
					$itemDescriptionParts = self::split($orderedItem['description']);

					foreach ($itemDescriptionParts as $itemDescription) {
						$itemDescriptionClean = removeSpecialChars($itemDescription);
						$output .= $itemDescriptionClean;
					}

					// Add price for pre receipt
					if ($_POST['pre_receipt']) {
						$output .= " - " . number_format($orderedItem['price_with_discount'], 2, '.', ',');
					}
					
					if (!$_POST['pre_receipt']) {
						if ($orderedItem['comments'] != '') {
							$output .= "   > " . removeSpecialChars(substr($orderedItem['comments'], 0, 27)) . "\n";
						}
					}

					/** Side dishes */
					if (isset($orderedItem['side_dishes']) && !$_POST['pre_receipt'])
					{
						foreach ($orderedItem['side_dishes'] as $side_dish) {
							$output .= "\n   + " . removeSpecialChars(substr($side_dish['description'], 0, 27)) . "\n";
						}
					}

					$output .= "\n";
				}
			}
		}

		/**
		 * Sums
		 */


		/**
		 * Footer
		 */
		$output .= "------------------------\n";

		if ($_POST['pre_receipt'])
		{
			$output .= "\nSubtotal: " . number_format($_POST['order']['subtotal'], 2, '.', ',') . "\n";
			$output .= "Discount: " . number_format($_POST['order']['discount'], 2, '.', ',') . "\n";
			$output .= "Total: " . number_format($_POST['order']['total'], 2, '.', ',') . "\n\n";
		}

		$output .= "Time: " . getTime() . "\n";

		return $output;
	}
	else
	{
		return 'EMPTY';
	}
}
Sep
15
1 month ago
Activity icon

Replied to New Default Page In Laravel 8

+1 I also really liked the old clean default page. More clutter is never good. Keep it simple.

Activity icon

Started a new Conversation Interface Naming Convention

If we should name our interfaces what they are like for example Human. Then we get into trouble when we need to extend a Human base class.

But on the other hand saying IHuman or HumanInterface seems verbose. What should we do in these kind of situations?

Class John extends Human implements Human
{

}