Ksandar

Ksandar

Member Since 3 Years Ago

Experience Points
122,960
Total
Experience

2,040 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
1103
Lessons
Completed
Best Reply Awards
14
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 25
122,960 XP
Apr
08
5 months ago
Activity icon

Awarded Best Reply on Validation Errors With Tailwind

@bensen you can use the standard @error blade directive, as is done in the basic login page view, like this:

<input class="form-control @error('email') border-red-500 @enderror" name="email">

using vue or js is not necessary for this

About this @error blade directive you can read here

Activity icon

Replied to Validation Errors With Tailwind

@bensen you can use the standard @error blade directive, as is done in the basic login page view, like this:

<input class="form-control @error('email') border-red-500 @enderror" name="email">

using vue or js is not necessary for this

About this @error blade directive you can read here

Apr
02
5 months ago
Activity icon

Awarded Best Reply on How Would You Maintain/update Your Codes In Production?

@untymage Well, first of all, you can pay attention to Envoyer. This is a tool for zero downtime deployment, it is not free, but easy. There is also a free course on it at laracasts so you can watch it to understand better what it is about. And even if you are not going to use envoyer, I still recommend that you look at this course to understand what a deploy is in principle.

Secondly, you can use free tools for deployment, which also allow you to configure zero downtime deployment, but instead of money, they will require your time to configure it. At first, this can be difficult until you figure it out and learn how to configure the deployment as you need.

For example, it may be a capistrano (and a package for deploying laravel applications). There are others, but since I did not work with them, I can’t talk about them.

And thirdly, I do not recommend using a bare git for deployment. Most likely it will be no zero downtime deployment.

Just imagine a situation: you modified your application, pushed it to the repository, went to the server and did git pull. At this point, your code has already been updated, but the migrations have not yet been migrated, new dependencies that was added to composer.json have not been installed, and no frontend has been compiled. As a result, you will have to do it all manually and your application at this time will not work correctly (or will be completely broken). And for production sites, this behavior is certainly not acceptable (of course, you can do all this in another folder, and then just swap them with the main one, but you still have to do it manually and all this will take a lot of time and effort. So deployment tools are designed to automate this process. Or you can simply enable maintenance mode for the duration of the upgrade, but that will not be zero downtime deployment, and the upgrade process will still require a lot of attention).

So to summarize, during the deployment you want not only update your code, but also take all the necessary steps to make it work correctly: update the code, update dependencies, perform migrations, compile the frontend, update the cache (for views, configs and routes at least), complete tasks specific to your application (if any) and only after that switch to the new version (and in case of an error at any of these steps do not switch).

I hope this helps you better understand what deployment is and where to look further.

Activity icon

Replied to Missing Episode

The same

Activity icon

Replied to How Would You Maintain/update Your Codes In Production?

@untymage Well, first of all, you can pay attention to Envoyer. This is a tool for zero downtime deployment, it is not free, but easy. There is also a free course on it at laracasts so you can watch it to understand better what it is about. And even if you are not going to use envoyer, I still recommend that you look at this course to understand what a deploy is in principle.

Secondly, you can use free tools for deployment, which also allow you to configure zero downtime deployment, but instead of money, they will require your time to configure it. At first, this can be difficult until you figure it out and learn how to configure the deployment as you need.

For example, it may be a capistrano (and a package for deploying laravel applications). There are others, but since I did not work with them, I can’t talk about them.

And thirdly, I do not recommend using a bare git for deployment. Most likely it will be no zero downtime deployment.

Just imagine a situation: you modified your application, pushed it to the repository, went to the server and did git pull. At this point, your code has already been updated, but the migrations have not yet been migrated, new dependencies that was added to composer.json have not been installed, and no frontend has been compiled. As a result, you will have to do it all manually and your application at this time will not work correctly (or will be completely broken). And for production sites, this behavior is certainly not acceptable (of course, you can do all this in another folder, and then just swap them with the main one, but you still have to do it manually and all this will take a lot of time and effort. So deployment tools are designed to automate this process. Or you can simply enable maintenance mode for the duration of the upgrade, but that will not be zero downtime deployment, and the upgrade process will still require a lot of attention).

So to summarize, during the deployment you want not only update your code, but also take all the necessary steps to make it work correctly: update the code, update dependencies, perform migrations, compile the frontend, update the cache (for views, configs and routes at least), complete tasks specific to your application (if any) and only after that switch to the new version (and in case of an error at any of these steps do not switch).

I hope this helps you better understand what deployment is and where to look further.

Activity icon

Awarded Best Reply on Get Roles Which Does Not Belong To A Specific User Id

@tomasam you can try this

public function edit($id) {
  $roles = Role:: whereDoesntHave('users', function($query) use($id) {
    $query->where('user_id', $id);
  })->get();
  ....
}
Activity icon

Replied to Get Roles Which Does Not Belong To A Specific User Id

@tomasam you can try this

public function edit($id) {
  $roles = Role:: whereDoesntHave('users', function($query) use($id) {
    $query->where('user_id', $id);
  })->get();
  ....
}
Mar
31
5 months ago
Activity icon

Awarded Best Reply on Displaying HTML Text From A Variable In A Blade

@carleogden hi, try this in blade

{!! $email_body !!}

You can reed more about it here (see "Displaying Unescaped Data" section)

Activity icon

Replied to Displaying HTML Text From A Variable In A Blade

@carleogden hi, try this in blade

{!! $email_body !!}

You can reed more about it here (see "Displaying Unescaped Data" section)

Activity icon

Replied to Does The Example Route In The Api.php Do Anything?

@brainmaniac You can freely remove it if it is not used in your application (in a fresh laravel installation it is not used, it's just an example). Or you can transfer return $request->user(); to the controller, if used.

Mar
30
5 months ago
Activity icon

Replied to Use Vue In Laravel Blade

@mykelcodex This can be achieved in various ways: for example, with the simplest

<div class="sidebar" v-if="this.$route.path !== '/login'">
Sidebar
</div>

or using nested routes (by transferring container with sidebar to vue and including them only on the necessary pages). Or you can come up with something else. It depends on the application you are trying to build.

I think that this topic is beyond the scope of one question and you better look for the appropriate guide or article. And read the vue router documentation

Activity icon

Awarded Best Reply on Use Vue In Laravel Blade

@mykelcodex you already setup vue in js/app.js. So remove

<script>
      var app = new Vue({
        el: '#app',
        data: {
          message: 'You loaded this page on ' + new Date().toLocaleString()
        }
      })
    </script>

and add data from it to your js/app.js like so:

const app = new Vue({
    el: '#app',
    data: {
        message: 'You loaded this page on ' + new Date().toLocaleString()
    },
    router: new VueRouter(routes)
});
Activity icon

Replied to Use Vue In Laravel Blade

@mykelcodex you already setup vue in js/app.js. So remove

<script>
      var app = new Vue({
        el: '#app',
        data: {
          message: 'You loaded this page on ' + new Date().toLocaleString()
        }
      })
    </script>

and add data from it to your js/app.js like so:

const app = new Vue({
    el: '#app',
    data: {
        message: 'You loaded this page on ' + new Date().toLocaleString()
    },
    router: new VueRouter(routes)
});
Mar
28
5 months ago
Activity icon

Awarded Best Reply on You Have Ventured Into 404 Space

@jlrdw I think html purifier is used here (on server side i mean). Usually, it should remove all unclosed tags (on saving or before showing post). But in this case, either there are bugs with it, or it should be more strict.

Anyway, @jeffreyway will now have something to do.

Maybe he will even make a video about it.

Activity icon

Replied to You Have Ventured Into 404 Space

@jlrdw I think html purifier is used here (on server side i mean). Usually, it should remove all unclosed tags (on saving or before showing post). But in this case, either there are bugs with it, or it should be more strict.

Anyway, @jeffreyway will now have something to do.

Maybe he will even make a video about it.

Activity icon

Replied to You Have Ventured Into 404 Space

@jlrdw {{ }} is used in vue. But in this case i think the problem in markdown parser (or html purifier) - it seems that it sometimes missing something and only after that vue comes into play.

Activity icon

Replied to You Have Ventured Into 404 Space

@jlrdw yeah, it's weird.

Activity icon

Replied to You Have Ventured Into 404 Space

although no, in the source code everything seems to be okay. Maybe really related to vue

Activity icon

Awarded Best Reply on This Action Is Unauthorized

@davieboy I'm not sure, but probably it related to the routes order. I suppose the request should go to the RepliesController, but an error occurs in the ThreadsController.

Please show your rotes/web.php

Perhaps your route file have two routes like these

Route :: delete ('/forum/{channel}/{thread}', 'ThreadsController @ destroy');
// ...
Route :: delete ('/forum/replies/{reply}', 'RepliesController @ destroy');

So the word replies match the {channel} as well. In that case you need change their order in the web.php

Activity icon

Replied to You Have Ventured Into 404 Space

noticed it too.

@jlrdw It looks like a problem with markdown parser

Activity icon

Replied to This Action Is Unauthorized

@davieboy I'm not sure, but probably it related to the routes order. I suppose the request should go to the RepliesController, but an error occurs in the ThreadsController.

Please show your rotes/web.php

Perhaps your route file have two routes like these

Route :: delete ('/forum/{channel}/{thread}', 'ThreadsController @ destroy');
// ...
Route :: delete ('/forum/replies/{reply}', 'RepliesController @ destroy');

So the word replies match the {channel} as well. In that case you need change their order in the web.php

Mar
27
5 months ago
Activity icon

Awarded Best Reply on Can Not Store Session Value.

@leostereo it looks like it's not a web route (specified not in web.php), so the session was not initialized. Or StartSession middleware was not included for this route.

Check your app/Http/Kernel.php class

/**
 * The application's route middleware groups.
 *
 * @var array
 */
protected $middlewareGroups = [
    'web' => [
        // ...
        \Illuminate\Session\Middleware\StartSession::class, // <- this middleware is responsible for initializing sessions
        // ...
    ],

    'api' => [
        'throttle:60,1',
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
    ],
];
Activity icon

Replied to Can Not Store Session Value.

@leostereo it looks like it's not a web route (specified not in web.php), so the session was not initialized. Or StartSession middleware was not included for this route.

Check your app/Http/Kernel.php class

/**
 * The application's route middleware groups.
 *
 * @var array
 */
protected $middlewareGroups = [
    'web' => [
        // ...
        \Illuminate\Session\Middleware\StartSession::class, // <- this middleware is responsible for initializing sessions
        // ...
    ],

    'api' => [
        'throttle:60,1',
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
    ],
];
Activity icon

Replied to View Missing After Rename. Laravel 7 - TDD App

@ajsmith_codes I think with experience it gets easier and easier. So just practice more and see more lessons here at laracasts. Personally, I learned a lot from them (and still learn). In the end, it all comes down to experience.

You can also pay attention to xdebug, but as for me it is better to pay more attention to TDD, I find it much more useful. Хdebug is really needed only on very complex projects, and for the rest, dump and dd are more than enough (but this is only my personal opinion).

And PHPStrom is a good choice, I use it too. You can look at the laracasts series on how to configure it, if you haven’t done so already.

Activity icon

Awarded Best Reply on View Missing After Rename. Laravel 7 - TDD App

@ajsmith_codes I remember this episode. Most likely updated remained in the database. Tests run migrations from scratch every time in their own separate database, so they return green.

Since this is a training project (which is still being developed in addition), you can simply refresh migrations

php artisan migrate:fresh

This will clear database, but the problem will be solved.

Activity icon

Replied to View Missing After Rename. Laravel 7 - TDD App

@ajsmith_codes I remember this episode. Most likely updated remained in the database. Tests run migrations from scratch every time in their own separate database, so they return green.

Since this is a training project (which is still being developed in addition), you can simply refresh migrations

php artisan migrate:fresh

This will clear database, but the problem will be solved.

Activity icon

Awarded Best Reply on Type-hint Custom Laravel Collection Items On Functions Like ->first()

@cannect i think you can do it by adding a method signature to your collection class

like this

/**
 * @method CartItem first(callable $callback = null, $default = null)
 */
class CartItems extends Collection
{
    //
}
Activity icon

Replied to Type-hint Custom Laravel Collection Items On Functions Like ->first()

@cannect i think you can do it by adding a method signature to your collection class

like this

/**
 * @method CartItem first(callable $callback = null, $default = null)
 */
class CartItems extends Collection
{
    //
}
Activity icon

Replied to Laravel Pagination Links

@floatinghero105 By id do you mean the html attribute? If so, you can export the view and change it as you need

php artisan vendor:publish --tag=laravel-pagination

more about this in the docs

Also note that pagination can be converted to json (docs). Maybe this is more suited to your needs.

Mar
26
5 months ago
Activity icon

Replied to Eloquent Get Data Using Last Relation Value

@yassineqoraiche it seems i dont understand something cause I still think my answer is correct. Unless changing it a little to suit your example (if User::PRIMARY_KEY_COLUMN_NAME ! = "id" and Book::USER_ID_COLUMN_NAME != "user_id"):

$results = User::addSelect(['last_book_status' => Book::select('status')
    ->whereColumn('users.'.User::PRIMARY_KEY_COLUMN_NAME, 'books.'.Book::USER_ID_COLUMN_NAME)
    ->latest()
    ->limit(1)
])->where('last_book_status', 'deleted')->get();

it will return a collection of users, whose latest book status = "deleted"

something like this (if cast to array)

array:2 [
  0 => array:7 [
    "id" => 2
    ....
    "last_book_status" => "deleted"
  ]
  1 => array:7 [
    "id" => 4
     ....
    "last_book_status" => "deleted"
  ]
]

If this is not what you need, then it would be nice to get a more detailed description of what you want get in the end

Аnd a little note: the addSelect method was added in Laravel 6, so if you use an earlier version, this will not work

Activity icon

Replied to Eloquent Get Data Using Last Relation Value

@yassineqoraiche what exactly is not working? The query is executed with an error or does not return the right users?

Mar
25
6 months ago
Activity icon

Replied to Eloquent Get Data Using Last Relation Value

@yassineqoraiche You can accomplish this with subquery

$users = User::addSelect(['last_book_status' => Book::select('status')
    ->whereColumn('users.id', 'books.user_id')
    ->orderBy('id', 'desc')
    ->limit(1)
])->where('last_book_status', 'deleted')->get();

Just keep in mind that subqueries may affect performance.

Activity icon

Awarded Best Reply on Laravel Record Doesn't Return It's Children

@sushiarkt I guess if Post::find($id)->photos is working you should define $with property on Post model like this

    /**
     * The relationships that should always be loaded.
     *
     * @var array
     */
    protected $with = ['photos'];

or use

Post::with('photos')->find($id)
Activity icon

Replied to Laravel Record Doesn't Return It's Children

@sushiarkt I guess if Post::find($id)->photos is working you should define $with property on Post model like this

    /**
     * The relationships that should always be loaded.
     *
     * @var array
     */
    protected $with = ['photos'];

or use

Post::with('photos')->find($id)
Activity icon

Commented on Project Activity Feeds: Cleanup

@tosinoginni Since Laravel 5.8 (see "Intermediate Table / Pivot Model Events" section) when using custom intermediate table models the applicable model events (like attaching, detaching, or syncing) will be dispatched

So I would suggest define such model for pivot table and make its own observer, where these events can be caught.

Mar
23
6 months ago
Activity icon

Replied to How To Add Condition "where Not Equal" In Validation ?

@mostafalaravel There is a "not in" rule for this purpose: https://laravel.com/docs/7.x/validation#rule-not-in

With your example, it will look like this

	$request->validate([
            'name' => 'required',
            'segments.*.builder' => 'required|not_in:abc',
            'segments.*.value' => 'required',
        ]);
Mar
22
6 months ago
Activity icon

Awarded Best Reply on Question About Rate Limiting

@michaeln The first request will create a requests counter in the cache and set its lifetime to 1 minute. The following requests will only increase the counter, but will not change its lifetime. Thus, if the time limit is set to 1 minute, then the counter will reset exactly 1 minute after the first request (when the cache expires).

And one more thing. If you exceed the limit, you will have to wait not exactly one minute, but until the cache expires. So if the time limit is set to 1 minute and you exceed the rate limit at 21th second, then you will have to wait only 39 seconds until the lock will be removed.

To better understand this logic, you can explore the RateLimiter class which is responsible for it

Activity icon

Replied to Question About Rate Limiting

@michaeln The first request will create a requests counter in the cache and set its lifetime to 1 minute. The following requests will only increase the counter, but will not change its lifetime. Thus, if the time limit is set to 1 minute, then the counter will reset exactly 1 minute after the first request (when the cache expires).

And one more thing. If you exceed the limit, you will have to wait not exactly one minute, but until the cache expires. So if the time limit is set to 1 minute and you exceed the rate limit at 21th second, then you will have to wait only 39 seconds until the lock will be removed.

To better understand this logic, you can explore the RateLimiter class which is responsible for it

Mar
21
6 months ago
Activity icon

Replied to Undefined Variable - Laravel 7 - Components

@diegoarbelaez it seems there are a bug with new blade components on some environments (see this issue)

btw, the problem may be in the class constructor. Try change your ContentHeader.php - rename $page_title to $pageTitle and add it to constructor attributes like this

<?php

namespace App\View\Components\layout;

use Illuminate\Support\Facades\Request;
use Illuminate\View\Component;

class ContentHeader extends Component
{
	/**
	 * @var string
	 */
	public $pageTitle;

         /**
	 * @var array
	 */
	public $breadcrumbs = [];
	
	/**
     	* Create a new component instance.
     	*
     	* @return void
     	*/
    	public function __construct($pageTitle = 'Some title')
    	{
       		//
		$this->pageTitle = $pageTitle;
		$crumb = new \stdClass();
	    	$crumb->label = 'Home';
	    	$crumb->active = false;
	    	$this->breadcrumbs[] = $crumb;
		   
	    	$crumb = new \stdClass();
	    	$crumb->label = $this->page_title;
	    	$crumb->active = true;
	    	$this->breadcrumbs[] = $crumb;
    	}

	/**
     	* Get the view / contents that represent the component.
     	*
     	* @return \Illuminate\View\View|string
     	*/
    	public function render()
    	{
        	return view('components.layout.content-header');
    	}
}
 	

And change content-header.blade.php accordingly

...
<h1 class="m-0 text-dark">{{ $pageTitle }}</h1>
...

And also run composer update if you use laravel less than v7.1.3 (or even run it anyway)

Mar
20
6 months ago
Activity icon

Awarded Best Reply on Fputcsv() Expects Parameter 2 To Be Array, Object Given

This should help

fputcsv($file, (array) $key);
Activity icon

Replied to Fputcsv() Expects Parameter 2 To Be Array, Object Given

This should help

fputcsv($file, (array) $key);
Activity icon

Replied to Undefined Variable - Laravel 7 - Components

Well, then maybe the problem in opcache

in this case opcache_reset() may help (or restarting the server).

I tried your code locally and it works fine. So I think the problem is in the server settings, not in your code

Activity icon

Replied to Undefined Variable - Laravel 7 - Components

Maybe a cache? Try run

php artisan view:clear

on the server